Results 1 to 3 of 3

Thread: How to get mouse events when button is disabled ?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    How to get mouse events when button is disabled ?

    I am making an app in WinForms. I created a new custom control, and inherited the Button.

    I override the OnMouseDown event, but I need to get the event even when the button is disabled, and this is not happening.

    How can I get mouse events when the button is disabled ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: How to get mouse events when button is disabled ?

    Quote Originally Posted by CVMichael View Post
    I override the OnMouseDown event
    No you don't. OnMouseDown is a method. It's the method that raises the MouseDown event. You override methods and you handle events.

    If the OnMouseDown method is not called then I think the next option would to override the WndProc method and see whether the control receives the corresponding messages from Windows. If not then I would think that you'd have to handle MouseDown for the parent and check whether it occurred within the bounds of your control. I'm not sure exactly what being disabled means under the hood but, if it means not receiving Windows messages, there's nothing you can really do about it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How to get mouse events when button is disabled ?

    Quote Originally Posted by jmcilhinney View Post
    If the OnMouseDown method is not called then I think the next option would to override the WndProc method and see whether the control receives the corresponding messages from Windows.
    Tried that, I'm not getting any mouse events when the button is not enabled
    Quote Originally Posted by jmcilhinney View Post
    If not then I would think that you'd have to handle MouseDown for the parent and check whether it occurred within the bounds of your control.
    How do I do that ?
    I tried this:
    Code:
    // in constructor:
    this.MouseDown += new MouseEventHandler(this.test_MouseDown);
    
    // then
    private void test_MouseDown(object sender, MouseEventArgs e)
    {
        object aa = sender; // test break point
    }
    and this executes right after the "OnMouseDown" method, which I already tried at the beginning:
    Code:
    protected override void OnMouseDown(MouseEventArgs e)
    {
        base.OnMouseDown(e);
    }
    Which gets called only when button is enabled

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width