PC Review


Reply
Thread Tools Rate Thread

How best to handle mouse events for custom drawn objects?

 
 
=?Utf-8?B?TXJOb2JvZHk=?=
Guest
Posts: n/a
 
      1st Sep 2006
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
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      5th Sep 2006
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]
- (E-Mail Removed)

"MrNobody" <(E-Mail Removed)> wrote in message
news:81A30F5A-750C-4B51-A197-(E-Mail Removed)...
> 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



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seeking advice - how to handle mouse events on custom drawn shapes trant Microsoft C# .NET 1 13th Nov 2009 01:17 AM
C# - Do we hav any methods to handle the mouse events sravan_reddy001 Microsoft C# .NET 1 6th Jun 2007 03:32 AM
Custom Control Mouse Events ahmed.maryam@gmail.com Microsoft C# .NET 2 7th Mar 2007 02:41 AM
Drawn Objects do not Appear John Microsoft Excel Discussion 0 23rd Mar 2005 09:55 AM
Mouse over events for Active X objects in excel Shrinu Microsoft Excel Programming 1 26th May 2004 10:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:31 AM.