简体   繁体   中英

How do I change the visual of a form after it has Initialized C# Visual Studio Windows Form App?

I'm trying to build test apps for practice. I work with forms and realised that I can't change the form appearance that already used InitializeComponent() in C# Visual Studio App.

My code:

public Form1()
{
    InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
   Form1 form1 = new Form1();
   form1.Size = new Size(50, 50);
}

Can anyone help me?

form1 is a brand new form, whose size you're setting, but which you're never showing.

All you need is:

private void button1_Click(object sender, EventArgs e)
{
   this.Size = new Size(50, 50);
}

Actually, the this is redundant, but makes it a bit clearer which form you're changing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM