GDI+ 绘制多行文本

绘制多行文本,如图:

 

思路主要设置drawstring的第二个参数的高度,这样就ok了。

代码如下;

View Code
        //private void Form1_Paint(object sender, PaintEventArgs e)
        
//{
        
//    Graphics g = e.Graphics;
        
//    FontFamily ff = new FontFamily(GenericFontFamilies.Serif);
        
//    Font f = new Font(ff, 12, FontStyle.Italic|FontStyle.Bold|FontStyle.Strikeout|FontStyle.Underline) ;
            
        
//    string str = "Heightfjdfjdkkkkkkhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhkkkkkkkkkkkkkkkkkkkkkkkkkfjdkkkkkkkkkkkkkkkkjf" + f.Height;
        
//    //不添加而外的高度
        
//    SizeF sf = g.MeasureString(str, f, int.MaxValue, StringFormat.GenericTypographic);
            
        
//    Rectangle r = new Rectangle(0, 0, 200, f.Height * 6);
        
//    g.DrawRectangle(Pens.Red,r);
        
//    g.DrawString(str, f, Brushes.Blue, r, StringFormat.GenericTypographic);
            

        
//}

 

 

posted on 2011-07-30 01:21  wtq  阅读(805)  评论(0编辑  收藏  举报