Simon Reich

Simon Reich

  • NA
  • 2
  • 564

opening contents in panel from form1 in another panel in form2

Dec 15 2022 7:18 PM

I have a panel with many labels in it on form1.

I would like to click a button (also on form1), which will open up new window form2 with another panel, which will contain the same labels (I am interested particularly in the backcolor).

pasteboard.co/k4qfx7UnbCEa.png

Only solution I was able to come up with is to make all labels in the panel on form1 public, give every single one of them another "name" and make clicking the button to open new form2 and making its labels the same properties.

public Label labelxx;

public Form1()

{

initializeComponent();

instance=this;

labelxxHome = labelxx;

}

private void button7_Click(object sender, EventArgs e)

{

Form2 f2 = new Form2();

Form2.instance.labelxxnewwindow.BackColor = labelxx.BackColor;

f2.Show();

}

 

while I will also make public labels in the form2.

 

But perhaps there is much easier solution? And will mine solution actually work? Thx a lot.


Answers (1)