Augusto Accorsi
Augusto Accorsi

Reputation: 327

Resize form by its child

I am doing a Windows Forms Application and I need to change Form2 size by Form1. I already tried it and didn't work.

Control control = this.Parent;
control.Size = new System.Drawing.Size(490, 380);
///// 

Parent.control.Size = new System.Drawing.Size(490, 380);   
///
Form2 main = new Form2();
main.Size = new System.Drawing.Size(490, 380);

Anyone could help?

Upvotes: 0

Views: 143

Answers (1)

cansik
cansik

Reputation: 2004

If you want to resize the main form when the second form is resized you have to add an event handler to the resize event:

Form second = new Form ();
second.Resize += (object sender, EventArgs e2) => this.Size = second.Size;

If you want to change the size of the main form when the user clicks a button or something else happens, you have to store a reference to the main form (e.g. as constructor parameter):

private readonly Form _parent;

public SecondForm (Form parent)
{
    _parent = parent; 
}

public void SomethingHappend ()
{
    _parent.Size = this.Size;
}

Upvotes: 1

Related Questions