You can inject another object to hold onto the references.
public class PanelSize
{
public int Width {get; set;}
public int Height {get; set;}
}
Here we have a holder for it in the Form that is receiving inputs.
public PanelSize Dimensions {get; set;}
Which changes the click event to be this:
private void BtnClick(object sender, EventArgs e) /->Button Event<-\
{
Dimensions.Width = int.Parse(textBox1.Text);
Dimensions.Height = int.Parse(textBox2.Text);
}
Then rather than doing a
Show()
you can do a
ShowDialog
. Then after the
ShowDialog()
runs you can capture the value and set it. If you require a
Show()
to work you will need to do some event triggering or actual binding.
Here is how you would do with
ShowDialog
public PanelDimensions Dimensions {get; private set;}
private void Enter(object sender, EventArgs e)
{
Dimensions = new PanelDimensions();
Form6 form2 = new Form2();
form2.Dimensions = Dimensions;
form
form2.ShowDialog();
panel1.Width = Dimensions.Width;
panel1.Height = Dimensions.Height;
}