private void MainForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Font font = new Font("Tahoma", 11, GraphicsUnit.Pixel);
SizeF size = e.Graphics.MeasureString(drawText, font);
this.Text = size.Width.ToString();
e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 0.0F, 0.0F, size.Width, size.Height);
e.Graphics.DrawString(drawText, font, Brushes.Black, new PointF(0, 0));
}
目前感觉取得的宽度像素值略大于理论值。明天继续完善之~
本文地址:http://com.8s8s.com/it/it7648.htm