Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generally, you do NOT want one Control to know about the other. Make your custom Controls expose events when something interesting happens and let the application code handle the logic to show/hide other controls.</p> <p>For example:</p> <pre><code>MyUserControl ctl = new MyUserControl; ctl.OnHideReports += OnHideReports; ctl.OnShowReports += OnShowReports; ... </code></pre> <p>Then in the event handler for OnHideReports, handle the logic:</p> <pre><code>void OnHideReports(...) { _reports.Hide(); _purchaseReports.Show(); ... } </code></pre> <p>Also, try to add your user controls to the Form using the WinForm designer. It is much easier to work with Controls from the designer versus declaring them directly in the code.</p> <p>Update:</p> <p>This example has two buttons on a form plus two user Controls. When Button 1 is clicked, it shows User Control 1 and hides User Control 2. When Button 2 is clicked, it does the reverse. Note that the buttons and user Controls are added to the form using the Forms designer, not manually in code. This will take care of positioning, adding them as child controls to the main form etc. Do not manually add them with your own code unless you have a good reason to do so.</p> <pre><code>public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void UiButtonOneClick(object sender, EventArgs e) { myUserControlOne.Show(); myUserControlTwo.Hide(); } private void UiButtonTwoClick(object sender, EventArgs e) { myUserControlOne.Hide(); myUserControlTwo.Show(); } } </code></pre>
 

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