Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to expose events in a WinForms custom control
    primarykey
    data
    text
    <p>I've developed a custom control that acts like a group box with a check box over the group label. The idea being, once the check box is unchecked all the controls in the group are disabled.</p> <p>I need to expose the Check changed event so that external actions could be performed if required. I've also exposed the Check state changed.</p> <p>Currently, when the control is used it changes the check state when any of the controls in the group loose focus.</p> <p>When I handle the check changed event, should I then re-fire the event for any external handlers?</p> <p><img src="https://i.stack.imgur.com/tzptj.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/NM8E1.jpg" alt="enter image description here"></p> <p>The events defined:</p> <pre><code>/// &lt;summary&gt; /// Event to forward the change in checked flag /// &lt;/summary&gt; public event EventHandler CheckedChanged; /// &lt;summary&gt; /// Event to forward the change in checked state of the checkbox /// &lt;/summary&gt; public event EventHandler CheckStateChanged; </code></pre> <p>The event handler code:</p> <pre><code>private void chkBox_CheckedChanged(object sender, EventArgs e) { // Disable the controls within the group foreach( Control ctrl in this.Controls ) { if( ctrl.Name != "chkBox" &amp;&amp; ctrl.Name != "lblDisplay" ) { ctrl.Enabled = this.chkBox.Checked; } } // Now forward the Event from the checkbox if (this.CheckedChanged != null) { this.CheckedChanged(sender, e); } } private void chkBox_CheckStateChanged(object sender, EventArgs e) { // Forward the Event from the checkbox if( this.CheckStateChanged != null ) { this.CheckStateChanged( sender, e ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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