I have a custom checkbox control that inherited from System.Windows.Forms.Control
and it hasn’t CheckedChanged event. I want to implement CheckedChange same as dot net native CheckBox. How can I do it well ?
I have a custom checkbox control that inherited from System.Windows.Forms.Control and it hasn’t CheckedChanged
Share
You are inheriting fromn Control, not CheckBox, so the solution is similar to the one proposed by Frigik, but it’s not exactly that one.
First of all you have to define the event in your class, i.e.:
In this way every developer using your control can subscribe/unsubscribe to the event. This is not enough, since the event will never be triggered. To do so, you have to define a method to trigger it, and the call this method whenever the state of your control changes:
Where this method will be called depends on the structure of your control. For instance if you have a property Checked, you could call the method in its setter: