Mouse selection

D

David

Hi all,

I have a picturebox control, that I am dynamically generating a graph of
points (vector drawing).

Now, what I need to do is when I hold my pointer on a plotted point (or
within a specified radius), I want to pop-up certain information about the
point. You know, like the circle that spins up and looks like a right
click... I want to be able to do something like this.

Any pointers would be appreciated.

Thanks.
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

dbgrick

The picturebox has a MouseDown event handler. Wire up the MouseDown event
handler and then use the x and y coordinates in the MouseEventArgs to
determine the location of the stylus on the graph. Then you create a form
that contains the info and show it to the user.

Regards,
Rick D.
 
D

David

Thank you, I was considering this route already, but what I would have
preferred is a 'context sensitive' type of pop-up. Basically, hold the
pointer down, get the dots rotating around the pointer and pop-up my
information.

Also on this pop-up I would also like to have a menu item that is possible
to delete the point that I have plotted.


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Thanks, I have found it...

I am now calculating the position of the mouse in the picturebox, but have
some slight problems.

PopupMenu.MenuItems.Clear();

MenuItem XPos = new MenuItem();

XPos.Text = "X : " + (MousePosition.X - GraphDisplay.Location.X);

MenuItem YPos = new MenuItem();

YPos.Text = "Y : " + (MousePosition.Y - GraphDisplay.Location.Y);

PopupMenu.MenuItems.Add(XPos);

PopupMenu.MenuItems.Add(YPos);


(My picturebox is called GraphDisplay).

I am trying to get the coordinates with reference to top left of picture
box, The X Position is perfect, the top position (Y) looks like it is taking
into account the title area (where the start button etc. is).

Is the title bar height consistent? How high is it? (Looking for "Start menu
height" on google doesn't show anything.)

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
 
C

Christopher Fairbairn

Hi,

David said:
I am trying to get the coordinates with reference to top left of picture
box, The X Position is perfect, the top position (Y) looks like it is
taking into account the title area (where the start button etc. is).

Is the title bar height consistent? How high is it? (Looking for "Start
menu height" on google doesn't show anything.)

Instead of trying to perform this kind of calculation manually take a look
at the PointToClient method available on the picture box control (see MSDN
documentation at
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.pointtoclient.aspx).

// Convert co-ordinates from screen space to client space.
Point pt = pictureBox1.PointToClient(new Point(MousePosition));

This will take a point measured in screen co-ordinates (such as the mouse
position) and perform the transformation required to convert it into client
co-ordinates (i.e. relative to the picture box).

Your X co-ordinate is probably looking correct due to it being a Windows
Mobile device where windows are fullscreen by default and hence the offset
between screen co-ordinates and form co-ordinates is zero on the x axis. If
your dialog was non fullscreen or running on a Windows CE device etc this
may not be the case.

Hope this helps,
Christopher Fairbairn
 
D

David

Thank you.

I currently have it working with the way I had written here, but I will
definately look at the PointToClient. That sounds a much more scalable way
of handling it (especially if I move or resize the picturebox (actually, the
way I have currently done it is mathematically using top, left, width and
height etc.))

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top