C# Resizing a form the programming way.
-
I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie
-
I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie
What's the exact error message? This works fine:
this.Height -= 150; // reduce height by 150 pixels
this.Width += 200; // increase width by 200 pixels
this.Height = 300; // set height to exactly 300 pixelsIf you want to change these values from outside the form, then you need to replace
this
with an instance variable of your form, like this:Form1 form = new Form1();
form1.Height = 200;regards
-
What's the exact error message? This works fine:
this.Height -= 150; // reduce height by 150 pixels
this.Width += 200; // increase width by 200 pixels
this.Height = 300; // set height to exactly 300 pixelsIf you want to change these values from outside the form, then you need to replace
this
with an instance variable of your form, like this:Form1 form = new Form1();
form1.Height = 200;regards
-
Thanks The second piece of code didn't work, but I played around with it and finally did get it to work. this.Height = 145; Hengy I like Pie
You can't directly access the
Form1
class and callHeight
as a static method. You need an instance of your Form1 object, which you already have, namelyform
Form1 form = new Form1(); // create our form
// ... display it, do other things with it
form.Height = 200; -
You can't directly access the
Form1
class and callHeight
as a static method. You need an instance of your Form1 object, which you already have, namelyform
Form1 form = new Form1(); // create our form
// ... display it, do other things with it
form.Height = 200; -
I am developing a serch application. I want to it to have a "Simple" option and an "Advanced" option. When I press the Simple button I want some options to disapear (which I can do) and the form to get smaller (reduce Height only). I need help with code for making the form smaller. I have tried using the MSDN site examples, but Visual Studio 2005 doesn't recognize: Form1.Height = 145 It says I need aditional information (System.Windows. etc.) Hengy I like Pie -- modified at 10:18 Sunday 4th June, 2006 Hengy I like Pie
Whenever you need to resize your form, you can reset the size property of your form like this.size=new Size(newWidth,newHeight) As soon as this line will be executed, you form will be resized. Here you can give the height and width whichever you want. But remember, you need to take into consideration the new sizes of your controls on the form since they may not look pretty with the resized form. That's it... Wasif Ehsan.