Click here to Skip to main content
15,921,174 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
I want to dynamically read the height and width while winform is sizable. That is, after running the form the value of these can be changed with the change of form size. If I use
C#
this.height or this.width
it can read only initial value.
Posted
Comments
Sergey Alexandrovich Kryukov 12-Mar-14 18:59pm    
Not true. And remember that C# is case-sensitive.
—SA

It's simple :)
C#
private void Form1_Resize(object sender, EventArgs e)
{
    label1.Text = this.Width + "," + this.Height;
}


-KR
 
Share this answer
 
No, the Height and Width properties reflect the current size of the form.
To prove it, add a label, and the following code to your Load event handler:
C#
private void Form1_Load(object sender, EventArgs e)
    {
    Timer t = new Timer();
    t.Interval = 100;
    t.Tick += new EventHandler(t_Tick);
    t.Start();
    }

Then add the handler:
C#
void t_Tick(object sender, EventArgs e)
    {
    label1.Text = string.Format("{0}:{1}", Width, Height);
    }
Run your app, and look at the label while you resize the form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900