这个方法怎么让字体居中显示啊,各位谁知道啊!
        StringFormat sf = new StringFormat();
        sf.Alignment = StringAlignment.Center;        
        sf.LineAlignment = StringAlignment.Center;
       
        System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        System.Drawing.Font f = new System.Drawing.Font("Verdana", 30);
        System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(180, 170, 140, 40));
        g.DrawString(membershow, f, b, 0,0,sf);
        g.Dispose();

解决方案 »

  1.   

            //
            // 摘要:
            //     在指定位置并且用指定的 System.Drawing.Brush 和 System.Drawing.Font 对象绘制指定的文本字符串。
            //
            // 参数:
            //   s:
            //     要绘制的字符串。
            //
            //   font:
            //     System.Drawing.Font,它定义字符串的文本格式。
            //
            //   brush:
            //     System.Drawing.Brush,它确定所绘制文本的颜色和纹理。
            //
            //   x:
            //     所绘制文本的左上角的 x 坐标。
            //
            //   y:
            //     所绘制文本的左上角的 y 坐标。
            //
            // 异常:
            //   System.ArgumentNullException:
            //     brush 为 null。- 或 -s 为 null。
            public void DrawString( string s, Font font, Brush brush, float x, float y );
      

  2.   

    g.DrawString(membershow, f, b, 图像长度除以2再减去字符占用长度的一半,图像长度除以2再加上字符占用长度的一半,sf); 
      

  3.   

    方法是对的..你的DrawString用法不对.只指定X Y 不知道大小..怎么才算居中呢.你参考下面的.
     Graphics _Grap =Graphics.FromHwnd(this.Handle);
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;            _Grap.DrawString("aaaa", this.Font, Brushes.Yellow, new Rectangle(0, 0, 100, 100), sf);
                _Grap.Dispose();
                
      

  4.   

       g.DrawImage(image, 0, 0, image.Width, image.Height); 
            System.Drawing.Font f = new System.Drawing.Font("Verdana", 30); 
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(180, 170, 140, 40)); 
            g.DrawString(membershow, f, b, new Rectangle(0,0,image.Width, image.Height),sf); 这个改下你的程序.不说了..累