473,626 Members | 3,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How best to handle mouse events for custom drawn objects?

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
1 2744
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.co m

"MrNobody" <Mr******@discu ssions.microsof t.comwrote in message
news:81******** *************** ***********@mic rosoft.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
3018
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For example dsParts.xsd and including that in the data tier. I then will create a class that looks like this Public Class CPart Inherits dsParts
1
7648
by: suhas | last post by:
Hi, I have an MDI app that allows user to create flowcharts. User can drag flowchart objects (squares, rectangles, elipses, etc) from the toolbar and put on a form. They should be able to move the objects around on the form. This is where the problem is, I have implemented this using the mouse_down, mouse_up and mouse_move events of the form. When user selects a object, I receive the
3
10046
by: Logan McKinley | last post by:
I need to draw a dot where ever the user clicks (which will be on either the form or a couple dynamically placed picture boxes). I thought the following code should work: //--- static public extern IntPtr WindowFromPoint(System.Drawing.Point Point); //... h = (System.Drawing.Point)hits; // this is an array of Point objects ip = WindowFromPoint(h);
14
3126
by: 42 | last post by:
Hi, Stupid question: I keep bumping into the desire to create classes and properties with the same name and the current favored naming conventions aren't automatically differentiating them... (both are "Pascal Case" with no leading or trailing qualifiers). For example... I'll be modelling something, e.g. a computer, and I'll
3
1271
by: Qwert | last post by:
Hello, if you have a WebCustomControl ( inherits from System.Web.UI.WebControls.WebControl ), how do you create an event that responses to the movement of the cursor above the control? System.Web.UI.WebControls.ImageButton can determine the location of the mouse relative to its origin. The 'tooltip' event can determine when the mouse is above the control.
10
1560
by: Miro | last post by:
I wanted certain text boxes ( only certain ones ) to always be Trim'd so that spaces are not in the begining, nor the end of the text entered. I created my own "Handle ?" - i hope thats the right terminology, and it works. Is this the right way to do this? I had to use DirectCast to get the textbox name. Private Sub TrimValues(ByVal sender As System.Object, ByVal e As EventArgs) _
0
2156
by: robson_king | last post by:
I am trying to use Microsoft.Ink to implement mouse gestures on a regular Windows pc (read not a tablet). So i have downloaded the Ink SDK and the Recognizers pack from the Table PC web site and got my application to draw ink and recognize gestures. Now what I am trying to do is only enable mouse gestures when the user clicks and moves with the right mouse button down. So I put the code to enable my inkcollector in the mouse move event
2
2116
by: MrNobody | last post by:
IF I am making a custom user control which draws stuff that might exceed its boundaries, can I get the user control to handle the scrolling for me? The AutoScroll property doesn't seem to be doing it. Do I have to set some special Size so it knows it's supposed to scroll? Currently by default behavior it is just clipping my content and not putting any scrollbar. and if I can somehow get the user control to add the scrollbar how can I...
0
6842
AHMEDYO
by: AHMEDYO | last post by:
Hi Every one... With this visual Basic 6.0 Code you can handle more event that visual basic Support as Mouse wheel and hover or you can control event before VB IDE Default Windows proc as WM_CREATE when windows start creation, this task is useful for some application , for example you can create new UI Control at run time using Form1.Control.add("vb.CommandButton","Cmd1") Function and you can handle command button event by WM_COMMAND Message...
1
8368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8512
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7203
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5576
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4094
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.