测试代码:
string str = "字符串";var width = TextRenderer.MeasureText(str, this.Font);var width2 = this.CreateGraphics().MeasureString(str, this.Font);
str = "字符串"时,结果为:
width:{Width=41, Height=12}
width2:{Width=41.06836, Height=15.1875}
AutoSize = true的Label尺寸为41, 12
str = "zifuchuan"时,结果为:
width:{Width=59, Height=12}
width2:{Width=59.68748, Height=13.5}
AutoSize = true的Label尺寸为59, 12
综合上述的结果,我取用TextRenderer.MeasureText作为最终获取字符串像素宽度的方法。