.net - How to call Parent Form method from Child Form in C#? -


i have parent form 1 method refresh panel content called resetpanel() . have button in parent form. if click button, new form opens up. changes , click on save. content gets saved in database , child form closes. parent form displayed.

i want call resetpanel() method now, panel shows updated values. how can achieve this?

if child form dialog one, can check form's dialog result:

// not forget release resources acquired:  // wrap idisposable using(..) {...} using (form mychildform = new mychildform()) {   //todo: if want pass main form child one:    // on result save "cancel" update panel   if (mychildform.showdialog() != dialogresult.cancel)      resetpanel(); } 

in case child not dialog can pass this child form reference main one:

  form mychildform = new mychildform(this);    mychildform.show(); // <- show, not showdialog()    ...    private mymainform m_mainform;    public mychildform(mymainform form) {     m_mainform = form;   }    private void save() {     //todo: save database here      // main form update     if (!object.referenceequals(null, m_mainform))       m_mainform.resetpanel(); // <- resetpanel should public or internal method   }    private savebutton_click(object sender, eventargs e) {     save();   } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -