社区
C#
帖子详情
如何设置label字符间距?
musclecn
2007-08-10 02:41:27
如何设置label字符间距? 是否需要重写?
...全文
435
6
打赏
收藏
如何设置label字符间距?
如何设置label字符间距? 是否需要重写?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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();
lable的行
间距
和字
间距
的
设置
根据要显示字体的多少,行
间距
,字
间距
的调整,计算出lable总的高度的方法,此demo简单易懂
怎样改变winform中
label
中文字的行距
这是一个类,相当于把
label
重写了,这样
label
然后就多了一个属性,调节属性就可以调节行距了
实现
label
文字以指定长度自动换行
系统自带的
label
不能自动换行,使用较不便,因此写了这个程序,实现了
label
的自动换行,其中有例子,在此与大家分享
彩色文字图生成组件,主要用来代替彩色
label
等
DrawTextOutLine Boolean 是否绘制文字描边 DrawTextShadow Boolean 是否绘制投影,不支持投影平移 Text String 源文,包含颜色代码的源文 TextRect Rectangle 给定区域边界,一般为欲
设置
结果图的控件大小 TextOutLineColor Color 文字描边颜色 TextFont Font 绘制文字的字体 TextRenderHint TextRenderHint
字符
渲染样式 TextBitmapSize Size 最终生成的结果图的大小 CharWidth Integer
字符
间距
增量 CharLine Integer
字符
行距增量 OutBitmap Bitmap 最终生成的结果图 OutputText String 过滤颜色代码后的内容
ios-UI
Label
的简单封装.zip
对UI
Label
做了一个简单的封装,对复制(复制时截取
字符
串,复制追加
字符
串),行
间距
,字
间距
,以及改变
label
中某段
字符
串的颜色和字体
C#
110,536
社区成员
642,578
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章