/// <summary> /// 计算文本的宽度 /// </summary> /// <param name="str"></param> /// <returns></returns> public static int GetStringLength(string str, int AddLength = 0) { Font f = new Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, GraphicsUnit.Pixel); Size sif = TextRenderer.MeasureText(str, f, new Size(0, 0), TextFormatFlags.NoPadding); return sif.Width + AddLength; //MessageBox.Show((sif.Width / pdi).ToString()); }