Help Ai pro Window Form C# thì vào giúp mình với!

Concopcon

Senior
Joined
Jun 27, 2014
Messages
319
Reactions
125
MR
0.002
Telegram
Chat with me via Yahoo Messenger
Facebook
Follow me on Facebook
Ai biết cách đều chỉnh Tên tiêu đề Form nằm giữa không ạ ! Xin chỉ giáo
 
space space space space space space space space space space space space :D:D:D:D:D
 
upload_2014-10-11_10-54-6.png

upload_2014-10-11_10-54-26.png


Bị lỗi này
 
Sao không làm VB trời!...:D
 
Code:
        public Form1()
        {
            InitializeComponent();
            this.Text="Bla bla bla bla";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Center_Text();
        }

        private void Center_Text()
        {
            Graphics g = this.CreateGraphics();
            Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
            Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
            String tmp = " ";
            Double tmpWidth = 0;
            while ((tmpWidth + widthOfASpace) < startingPoint)
            {
                tmp += " ";
                tmpWidth += widthOfASpace;
            }
            this.Text = tmp + this.Text.Trim();
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            Center_Text();
        }
 
Last edited:
làm sao space đc
mỗi màn hình mỗi pixel khác nhau , zom to phóng nhỏ
space vỡ sao
bỏ lâu r nên k hổ trợ đc thớt
nhưng nhớ man máng là trong propertie có thì phỉa , click qua tab thứ 2
 
Code:
        public Form1()
        {
            InitializeComponent();
            this.Text="Bla bla bla bla";
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Center_Text();
        }

        private void Center_Text()
        {
            Graphics g = this.CreateGraphics();
            Double startingPoint = (this.Width / 2) - (g.MeasureString(this.Text.Trim(), this.Font).Width / 2);
            Double widthOfASpace = g.MeasureString(" ", this.Font).Width;
            String tmp = " ";
            Double tmpWidth = 0;
            while ((tmpWidth + widthOfASpace) < startingPoint)
            {
                tmp += " ";
                tmpWidth += widthOfASpace;
            }
            this.Text = tmp + this.Text.Trim();
        }

        private void Form1_SizeChanged(object sender, EventArgs e)
        {
            Center_Text();
        }

code của bác, mình sử dụng vào thì phải chỉnh cửa sổ nữa thì nó mới nằm ở giữa, bác biết cách cho nó tự động theo kích thước cửa sổ ko ^^
 
code của bác, mình sử dụng vào thì phải chỉnh cửa sổ nữa thì nó mới nằm ở giữa, bác biết cách cho nó tự động theo kích thước cửa sổ ko ^^
Nhét nó trong hàm SizeChanged rồi mà ??

private void Form1_SizeChanged(object sender, EventArgs e)
{
Center_Text();
}
 
Mak hàm SizeChanged nằm ở đâu z bác >.<
Bạn hỏi vầy nữa thì mình bó tay, thôi bạn nghỉ học lập trình luôn đi cho đỡ tốn tiền :cool:
 

Announcements

Today's birthdays

Forum statistics

Threads
418,636
Messages
7,074,097
Members
170,738
Latest member
topsonvn

Most viewed of week

Most viewed of week

Back
Top Bottom