开发者

Visual C#: Adjust Form Size

开发者 https://www.devze.com 2023-01-06 16:54 出处:网络
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:

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);


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;
}


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.
}


You are trying to access a static property that doesn't exist. You need to reference the non static method that does exist.

If the options_Click method is inside of your FileSortForm.

this.Height = 470;

If the options_Click method is outside of the FileSortForm you have to use the reference. Something like:

subForm.Height = 470

Edit:

Inside of the containing class the 'this' qualify is unnecessary (unless you are calling an overridden method).

0

精彩评论

暂无评论...
验证码 换一张
取 消