I have a disabled from element and I want to enable it on double-click.
The problem is the DoubleClick handler only gets called when Foo.Enabled = True. When it's disabled, the handler doesn't received the double-click event.
this.Foo.DoubleClick += new System.EventHandler(this.Foo_OnDoubleClick);
// Handler
private void Foo_OnDoubleClick(object sender, EventArgs e)
{
Console.WriteLine("Double click");
}
Is there any workaround to this?
Create your own control inheriting from its base control (FOO) and override the Enable behavior. That way you will be able to make it behave the way that you wish.
EXAMPLE:
public class MyControl : Button //Example control
{
//Override and/or implement what you need in this control
public MyControl()
{
}
protected override void OnEnabledChanged(EventArgs e)
{
// Do whatever you wish to do
}
}
I still want to prevent users from entering a value when it is disabled.
Your question makes it sounds like you want to apply this to any control, but then your comment makes it sounds like you want to apply it to a TextBox.
If the latter case is true, set the TextBox.ReadOnly property to True instead of disabling the control.
Users will not be able to edit the value, but the double-click event will still fire.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With