By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 972 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

How best to handle mouse events for custom drawn objects?

P: n/a
I'm going to be creating shapes in a OnPaint method of an extended Panel
object, and I need mouse event functionality (onClick, onMouseOver) that kind
of stuff... what's the best way to go about doing this? Are there any design
patterns, algorithms for best performance?

Best way to translate mouse's x,y coords into a shape on my Panel
Sep 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
MrNobody,

The best way I can think of doing this would be to have a class that
represents the shapes that you are going to perform hit tests against. Of
course, you would start off from an abstract class.

This class would have two methods, one to indicate the max rectangle
that it could represent, given the shapes size, and then a method to see if
the coordinates actually fall within the shape. The reason for two passes
is that some shapes could be overly complex, and finding out if a point
exists in the shape could be a lengthy calc. This way, by saying "the max
area that my shape can take up is this", you can perform a simple calc to
see if the point has a shot of existing in the shape. If it does, you can
then do the second, lengthy calc and see if the point falls in the shape.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"MrNobody" <Mr******@discussions.microsoft.comwrote in message
news:81**********************************@microsof t.com...
I'm going to be creating shapes in a OnPaint method of an extended Panel
object, and I need mouse event functionality (onClick, onMouseOver) that
kind
of stuff... what's the best way to go about doing this? Are there any
design
patterns, algorithms for best performance?

Best way to translate mouse's x,y coords into a shape on my Panel

Sep 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.