문제

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.

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top