質問する質問する
 

質問DrawJapaneseStringの不具合なのでしょうか?

  • 2009年3月6日 15:32まつしろー ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     コードあり
    WindowsVista, VS2008, C#の環境にて、

    UserControl (=ScrollableControl)から派生したコントロールを作成しています。

    [1] 確認事項 - スクロールでの動作

        [動作]
            AutoScroll = true, AutoScrollMinSize を 適当な値に設定。

            OnPaint にて、スクロール位置を考慮した上で (下ソースのように)
            DrawJananeseString を 使用して文字列を描画する。
        
    base.OnPaint( e );  
    e.Graphics.TranslateTransform( AutoScrollPosition.X, AutoScrollPosition.Y );  
     


        [症状]

            スクロールさせると、
            正確な位置(Y方向)に文字列が描画されない(以下の2点の症状が出ます)。

            ☆ 文字列が完全に描画されない
            ☆ 全く違う位置に描画される


    [2] ビットマップへの DrawJapaneseString を使用した文字列描画

        [動作]

            ビットマップを作成し、そのビットマップに メイリオフォントで、DrawJapaneseString で文字列を描画。


        [症状]
            メイリオフォントとは思えないほど、文字が崩れる。

    1 protected override void OnPaint( PaintEventArgs e )  
    2 {  
    3     TextAlignmentStyleInfo  tasi = new TextAlignmentStyleInfo();  
    4     Bitmap                  bmp = new Bitmap( 300, 300, e.Graphics );  
    5     String                  strDraw = "テスト文字列";  
    6  
    7     using ( Graphics drawg = Graphics.FromImage( bmp ) ){  
    8         drawg.FillRectangle( Brushes.AliceBlue, 0, 0, 300, 300 );  
    9  
    10         using ( Font fnt = new Font( "メイリオ", 12.0F ) ) {  
    11             SizeF     sz = e.Graphics.MeasureString( strDraw, fnt );  
    12             Int32     iWidth, iHeight;  
    13             Rectangle rctDraw;  
    14  
    15             iWidth = (Int32)Math.Ceiling( sz.Width ) + 100;  
    16             iHeight = (Int32)Math.Ceiling( sz.Height );  
    17             rctDraw = new Rectangle( 10, 10, iWidth, iHeight );  
    18             Utility.DrawJapaneseString( drawg, strDraw, fnt, Color.Black, rctDraw, tasi, null );  
    19             drawg.DrawString( strDraw, fnt, Brushes.Black, new Point(10,100) );  
    20         }  
    21     }  
    22     e.Graphics.DrawImage( bmp, new Point(10,10) );  
    23     bmp.Dispose();  
    24 }  
    25  

すべての返信

  • 2009年3月17日 5:52頃末和義MSFT, モデレータユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
     まつしろーさん

    ご報告ありがとうございます。
    ただいま調査しております。

    今後ともよろしくお願いいたします。


    マイクロソフト