enter image description here

Tell panelSetting how to clear the panelSetting in the form FormSetting when you click on the button in FormMain

It seems to have installed Public everywhere but it does not come out, an error about the need to reference an object.

  • You have FormSetting formSetting ... in the code FormSetting formSetting ... Use formSetting.panelSetting.Controls.Clear(); - Igor
  • Then FormSetting would be black, and so it indicates that the name of the form with a capital letter exists. - Vitokhv
  • In the underlined line of the code in the picture, FormSetting is a type. You need an object reference. - Igor
  • I do not know how to create a link to an object, in Google too complex examples. - Vitokhv
  • @Vitokhv you have already created it somewhere, now you need to find it in your own code - Pavel Mayorov

1 answer 1

You must have a code somewhere that runs the FormSettings form. It should be something like this:

 FormSettings formSettings; private void button1_Click_1(object sender, EventArgs e) { formSettings = new FormSettings(); formSettings.Show(); } 

To clean the panelSetting you can write:

 private void button2_Click(object sender, EventArgs e) { if (formSettings != null) formSettings.panelSettings.Controls.Clear(); } 
  • In the code, even in the new project there is no FormSettings formSettings; line FormSettings formSettings; where to find her? - Vitokhv
  • Where can she be in a new project? You must add this form and the panel on it. Or I do not understand something? You wrote Tell me how to clean the panelSetting in the FormSetting form , that is, you must have the FormSetting form on which there is a panelSetting that you want to clear. - koshe
  • Recreated the question: ru.stackflowflow.com/questions/692914 - Vitokhv