如何设置label字符间距?

musclecn 2007-08-10 02:41:27
如何设置label字符间距? 是否需要重写?
...全文
435 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
musclecn 2007-08-13
  • 打赏
  • 举报
回复
2005可以手动调整的
??
可以吗?
xwk789xwk 2007-08-10
  • 打赏
  • 举报
回复
友情帮顶
lovefootball 2007-08-10
  • 打赏
  • 举报
回复
可以试试Graphics.DrawString

Graphics 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();
wwch369 2007-08-10
  • 打赏
  • 举报
回复
2005可以手动调整的
冰萍子 2007-08-10
  • 打赏
  • 举报
回复
没有研究过,继续关注~~
musclecn 2007-08-10
  • 打赏
  • 举报
回复
找到这段代码 但是不会用:
[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();

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧