[.net] PerformClick on a Panel?

Started by
2 comments, last by TheTroll 16 years, 9 months ago
Hi all, I need to simulate a mouse click on a panel, but I don't know how to do that. I've read that I could use win32 SendMessage(), but for a couple of reasons (possible future use with mono being one of them) I would prefer a pure .Net alternative. Is there a way to raise a Click event on a control just like PerformClick() does on buttons? Thank you.
Advertisement
Create a MouseEventArgs whose Button property is set to the System.Windows.Forms.MouseButtons.Left value.

Then call the OnMouseClick method with this MouseEventArgs as the argument on the Panel you are using.

That will do what you need.
theTroll
Quote:Original post by TheTroll
Create a MouseEventArgs whose Button property is set to the System.Windows.Forms.MouseButtons.Left value.

Then call the OnMouseClick method with this MouseEventArgs as the argument on the Panel you are using.

That will do what you need.
theTroll


Thank you but aren't these handlers protected? Anyway I was able to solve my problem: I would have preferred to generate the event, but the workaround I used should do the job.
Thank you again.
Yes it is protected but you can create your own public method and put it in your own panel. Then just call the base class method.

theTroll

[Edited by - TheTroll on July 18, 2007 11:58:44 AM]

This topic is closed to new replies.

Advertisement