Form的text 居中显示

Graphics g = this.CreateGraphics();
            //光标居中
            Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
            Double ws = g.MeasureString("*", this.Font).Width;
            String tmp = " ";
            Double tw = 0;
            //右移
            while ((tw + ws) < startingPoint)
            {
                tmp += "1 ";
                tw += ws;
            }
            this.Text = tmp.Replace("1", " ") + this.Text.Trim();

 

你可能感兴趣的:(Form的text 居中显示)