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

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

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


Bị lỗi này
 

tunvit

Vip
Verified
Joined
Jun 5, 2011
Messages
3,681
Solutions
1
Reactions
11,906
MR
46.434
Chat with me via Yahoo Messenger Chat with me via Teams
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:

hungzany

Banned
Joined
Feb 3, 2012
Messages
199
Reactions
93
MR
0.000
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();
}
 

InfiniteWarez

Junior
Joined
Mar 2, 2014
Messages
200
Reactions
93
MR
0.000
Chat with me via Teams

Announcements

Forum statistics

Threads
434,216
Messages
7,321,255
Members
185,478
Latest member
mayvanphongnc
Back
Top Bottom