|
-
Jun 9th, 2022, 05:33 PM
#1
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 ?
-
Jun 9th, 2022, 08:38 PM
#2
Re: How to get mouse events when button is disabled ?
 Originally Posted by CVMichael
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.
-
Jun 10th, 2022, 02:05 PM
#3
Re: How to get mouse events when button is disabled ?
 Originally Posted by jmcilhinney
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
 Originally Posted by jmcilhinney
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|