Question

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?

Était-ce utile?

La solution

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
    }
}

Autres conseils

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.

You Should handle mouse double click event of Parent(all double click goes to Enabled parent) then by check mouse location returned by event against each disabled control rectangle you can determine which control has been clicked.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top