(WinForm)label控件变形时,如何让字体随其一起变形?谢谢先 如题,在拉伸、扭曲label控件时,怎么才能让字体随着一起变形? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 how to twist label control?? LZ说的“拉伸、扭曲label控件”,应该是指设计的时候吧,运行的时候好像没法拉伸的。这个思路不知道行不行……先把AutoSize改成false,然后在InitializeComponent()里写一行:this.Font.Size = f( this.Height, this.Width );比如this.Font.Size = 0.5 * this.Height 不是设计的时候,是在程序运行的时候。控件的拉伸等操作我已经实现了。只是text内容不会跟着控件变化而变化。希望大家帮忙 处理Label的SizeChanged事件,或者继承Label,重写SizeChanged事件 maybe you need draw text by yourself, before draw text using Graphics.MultiplyTransform .. 我用了9楼haiwangstar兄弟的方法。并且使用了以下方法重绘(在label拉伸的时候发生): Font stringFont = new Font(this.Font.FontFamily, this.Height - 3); SizeF stringSize = new SizeF(); stringSize = this.CreateGraphics().MeasureString(this.Text, stringFont); GraphicsPath path = new GraphicsPath(); path.AddString(this.Text, stringFont.FontFamily, (int)FontStyle.Regular, stringFont.Size, new Point(0, 0), new StringFormat()); PointF[] dataPoints = path.PathPoints; byte[] pTypes = path.PathTypes; Matrix matrix = new Matrix(this.Width / stringSize.Width, 0.0f, 0.0f, 1f, 0.0f, 0.0f); matrix.TransformPoints(dataPoints); GraphicsPath newpath = new GraphicsPath(dataPoints, pTypes); e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; //e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;(注释掉这一句后,拉伸的情况下字体看不清楚) SolidBrush brush = new SolidBrush(this.ForeColor); e.Graphics.FillPath(brush, newpath); brush.Dispose(); stringFont.Dispose(); path.Dispose(); matrix.Dispose();结果是重绘后的字体比较模糊,特别是字体小的时候。不知道大家重绘的时候是不是也这样?vs本身控件的绘制怎么就那么清晰呢? 登录页面中注册按钮不响应 C#实现远程关机功能(windows和linux)源码实例 WMI访问权限问题 关于用C#写一个邮件收发程序 有个关于c#的问题 悄悄地我来了,悄悄地被拒绝~~~~~~ c# 关于SqlDataReader 的关闭问题 如何在IE中嵌入WinForm的程序? 告急 關於Log4Net日誌文件按日期輸出的問題。一直不成功。 怎么得到ListView中所选项的某一列的值?
这个思路不知道行不行……
先把AutoSize改成false,然后在InitializeComponent()里写一行:
this.Font.Size = f( this.Height, this.Width );
比如
this.Font.Size = 0.5 * this.Height
Font stringFont = new Font(this.Font.FontFamily, this.Height - 3);
SizeF stringSize = new SizeF();
stringSize = this.CreateGraphics().MeasureString(this.Text, stringFont);
GraphicsPath path = new GraphicsPath();
path.AddString(this.Text, stringFont.FontFamily, (int)FontStyle.Regular, stringFont.Size, new Point(0, 0), new StringFormat());
PointF[] dataPoints = path.PathPoints;
byte[] pTypes = path.PathTypes;
Matrix matrix = new Matrix(this.Width / stringSize.Width, 0.0f, 0.0f, 1f, 0.0f, 0.0f);
matrix.TransformPoints(dataPoints);
GraphicsPath newpath = new GraphicsPath(dataPoints, pTypes);
e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
//e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;(注释掉这一句后,拉伸的情况下字体看不清楚)
SolidBrush brush = new SolidBrush(this.ForeColor);
e.Graphics.FillPath(brush, newpath);
brush.Dispose();
stringFont.Dispose();
path.Dispose();
matrix.Dispose();
结果是重绘后的字体比较模糊,特别是字体小的时候。不知道大家重绘的时候是不是也这样?vs本身控件的绘制怎么就那么清晰呢?