Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C#: Adjust Form Size

Tags:

c#

winforms

I've been trying to use a button to extend the size of my form. However, for some reason, it won't let me do this. I'd think this would be an easy thing to accomplish, but I get the error:

"An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Control.Width.get'

The code I'm using that causes that error is

    private void options_Click(object sender, EventArgs e)
    {
        FileSortForm.Height = 470;
    }

FileSortForm is the name of my Form. Also, from the advice of another site, I added this code into the Form Load code.

this.Size = new System.Drawing.Size(693, 603);
like image 975
muttley91 Avatar asked Dec 29 '22 11:12

muttley91


2 Answers

You need to change the height of a specific instance of your form. Most likely in your case this will be the instance you want to modify:

private void options_Click(object sender, EventArgs e)
{
    this.Height = 470;
}
like image 182
heavyd Avatar answered Jan 05 '23 01:01

heavyd


It seems that FileSortForm is the name of your class, not your form instance. If this is the case, you can simply write

private void options_Click(object sender, EventArgs e)
{
    this.Height = 470; // "this" is your form instance.
}
like image 25
Humberto Avatar answered Jan 05 '23 00:01

Humberto