How To Center Align the Title Bar text In Windows Form?

前端 未结 4 895
不思量自难忘°
不思量自难忘° 2021-01-03 04:00

I am developing a Windows Form Application. I want to Align the Text to Center or say to Right of Title Bar of Form. How can I do it ??

4条回答
  •  死守一世寂寞
    2021-01-03 04:23

     Graphics g = this.CreateGraphics();
            double fw = this.Width; // form width
            double tw = g.MeasureString(this.Text.Trim(), this.Font).Width; \\ text width
            double rp = (fw - tw) / 2;
            int tt = Convert.ToInt32(rp); 
            string st = " ";
            st = st.PadRight(tt / 3);
            this.Text = st + this.Text.Trim();
    

提交回复
热议问题