Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should just pass the MainForm to the SearchForm, this way before you close the search form you will be able to hide the original MainForm without creating a new one. See the code bellow :</p> <pre><code>public class MainForm:Form { private SearchForm searchForm;//for keeping the search form public MainForm()//your main form constructor { } this.searchBtn.Click+=(s,e)=&gt; { if(this.searchForm == null) { this.searchForm = new SearchForm(this);//creating new searchForm if it does no exist this.searchForm.Show(); this.Enabled = false; } }; } public class SearchForm:Form { private MainForm mainForm;//this will keep the original mainform public SearchForm(MainForm mainForm) { this.mainForm = mainForm; } this.OnFormClosing+=(s,e)=&gt; { this.mainForm.Enabled = true; }; } </code></pre> <p>This will close the search form every time and create a new instance of it when you click the search button. If you want to hide it you should use this code : </p> <pre><code>public class MainForm:Form { private SearchForm searchForm;//for keeping the search form public MainForm()//your main form constructor { } this.searchBtn.Click+=(s,e)=&gt; { if(this.searchForm == null) { this.searchForm = new SearchForm(this);//creating new searchForm if it does no exist this.searchForm.Show(); this.Enabled = false; } else { this.Enabled = false; this.searchForm.Show(); } }; } public class SearchForm:Form { private MainForm mainForm;//this will keep the original mainform public SearchForm(MainForm mainForm) { this.mainForm = mainForm; } this.OnFormClosing+=(s,e)=&gt; { e.Cancel = true; this.mainForm.Enabled = true; this.Hide(); }; } </code></pre> <p>basically this is the easiest way to do this without complicated events and so on. I hope this solves your issue if not i am here to help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload