How to implement enable/disable for control

  • Thread starter Thread starter bartlomiej.szafraniec
  • Start date Start date
B

bartlomiej.szafraniec

Hi!
I'm trying to implement custom button. But I don't want to extend
Button class.
I want to extend Control class.
I want to implement Enable disable functionality.
But unfortunatly when control is in Enable = false state the on click
event is not called but that event is passed to parent object.
How to convince my custom button class not to pass Click events to
parent classes when my class is in Disabled state?

Thanks in advance
 
I'm trying to implement custom button. But I don't want to extend
Button class.
I want to extend Control class.
I want to implement Enable disable functionality.
But unfortunatly when control is in Enable = false state the on click
event is not called but that event is passed to parent object.
How to convince my custom button class not to pass Click events to
parent classes when my class is in Disabled state?

Unfortunately, if the Button is disabled, it will not receive mouse events,
which means events pass on to the button's parent control.

Off the top of my head, I can think of two options, both a little tricky:

1. Create a transparent control and place it over your disabled control.
Then monitor for mouse events in your transparent control. Here's how to
make controls transparent:

http://www.c-sharpcorner.com/Code/2003/May/TransparentControls.asp

2. Monitor for the mouse clicks in your parent control, then pass them to
your custom button.
 
Hi,

You could inherit from Control and override WndProc , detect the onclick
event, check for Enable and if so do not send the event to the parent.
Like this:

protected override void WndProc(ref Message m)
{
if (m.Msg == WM_XXXX && !this.Enabled)
return;
base.WndProc(ref m);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top