1
Graphics g = this.CreateGraphics();
2
SizeF sizeF = g.MeasureString("A", new Font("宋体", 9));
3
MessageBox.Show(sizeF.Width + " " + sizeF.Height);
4
g.Dispose();
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1 private void MeasureText1(PaintEventArgs e)
2 {
3 String text1 = "Measure this text";
4 Font arialBold = new Font("Arial", 12.0F);
5 Size textSize = TextRenderer.MeasureText(text1, arialBold);
6 TextRenderer.DrawText(e.Graphics, text1, arialBold,
7 new Rectangle(new Point(10, 10), textSize), Color.Red);
8 }
9
2 {
3 String text1 = "Measure this text";
4 Font arialBold = new Font("Arial", 12.0F);
5 Size textSize = TextRenderer.MeasureText(text1, arialBold);
6 TextRenderer.DrawText(e.Graphics, text1, arialBold,
7 new Rectangle(new Point(10, 10), textSize), Color.Red);
8 }
9