Winform中获取一串字符串所占用的像素宽度

时间:2022-08-22 22:29:27

转:csdn

 

Graphics g = Graphics.FromHdc(this.Handle);
            SizeF size = g.MeasureString("*",this.Font);
size 里面宽,高

 

TextRenderer.MeasureText("blblblblbl",this.Font,new Size(int.MaxValue, int.MaxValue), TextFormatFlags.NoPadding).Width;