如何设置label字符间距? 如何设置label字符间距? 是否需要重写? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 找到这段代码 但是不会用: [DllImport("gdi32.dll", CharSet=CharSet.Auto)] public static extern int SetTextCharacterExtra(IntPtr hdc,int nCharExtra); Font f= new Font("宋体",20); Brush b= new SolidBrush(Color.Green); String s="11111"; IntPtr hwnd = new IntPtr(); hwnd = this.Handle; Graphics g = Graphics.FromHwnd(hwnd); IntPtr hdc = g.GetHdc(); SetTextCharacterExtra(hdc,40); using(Graphics gg = Graphics.FromHdc(hdc)) { gg.DrawString(s,f,b,0,0); } g.ReleaseHdc(hdc); g.Dispose(); 可以试试Graphics.DrawStringGraphics g = this.CreateGraphics(); string strValue = "Hello World"; StringFormat myformat = new StringFormat(); myformat.Alignment = StringAlignment.Center; myformat.LineAlignment = StringAlignment.Center; myformat.FormatFlags = StringFormatFlags.FitBlackBox; Font fnt = new Font( "宋体",10f ); Rectangle rect = new Rectangle( 300, 300, 170, 30 ); SizeF size = g.MeasureString( strValue, fnt ); Bitmap bit = new Bitmap( (int)(size.Width), (int)(size.Height) ); Rectangle rectBase = new Rectangle( 0, 0, bit.Width, bit.Height ); Graphics gImage = Graphics.FromImage( bit ); gImage.DrawString( strValue, fnt, Brushes.Black, rectBase, myformat ); gImage.Save(); //Stretch image to specific width rect.X = rect.Top + ( rect.Height - rectBase.Height ) / 2; rect.Height = rectBase.Height; g.DrawImage( bit, rect, rectBase,GraphicsUnit.Pixel ); gImage.Dispose(); bit.Dispose(); 急求C#窗体解答 利用openxml合并Excel2010单元格的问题 c#操作AD用户 (顶者有分)突然想自己写控件了,请大家给点资源。(书,文章,源码都可)最好是入门级别的。 接口的编程,哪位有相关的资料呢? 问一个超级菜的问题 水晶报表是否可以实现报表的连续打印功能,也就是不分页打印? 读取文本文件的问题 向DataSet中加入行导致程序死机,什么原因? 如何重载WORD方法?? girdview中关于select类型按钮的问题 如何取得对象的名称
[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
public static extern int SetTextCharacterExtra(IntPtr hdc,int nCharExtra); Font f= new Font("宋体",20);
Brush b= new SolidBrush(Color.Green);
String s="11111";
IntPtr hwnd = new IntPtr();
hwnd = this.Handle;
Graphics g = Graphics.FromHwnd(hwnd);
IntPtr hdc = g.GetHdc();
SetTextCharacterExtra(hdc,40);
using(Graphics gg = Graphics.FromHdc(hdc))
{
gg.DrawString(s,f,b,0,0);
}
g.ReleaseHdc(hdc);
g.Dispose();
string strValue = "Hello World";
StringFormat myformat = new StringFormat();
myformat.Alignment = StringAlignment.Center;
myformat.LineAlignment = StringAlignment.Center;
myformat.FormatFlags = StringFormatFlags.FitBlackBox;
Font fnt = new Font( "宋体",10f );
Rectangle rect = new Rectangle( 300, 300, 170, 30 );
SizeF size = g.MeasureString( strValue, fnt );
Bitmap bit = new Bitmap( (int)(size.Width), (int)(size.Height) );
Rectangle rectBase = new Rectangle( 0, 0, bit.Width, bit.Height );
Graphics gImage = Graphics.FromImage( bit );
gImage.DrawString( strValue, fnt,
Brushes.Black,
rectBase, myformat );
gImage.Save();
//Stretch image to specific width
rect.X = rect.Top + ( rect.Height - rectBase.Height ) / 2;
rect.Height = rectBase.Height;
g.DrawImage( bit, rect, rectBase,GraphicsUnit.Pixel );
gImage.Dispose();
bit.Dispose();