Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Mouse Position (Read 2093 times)
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Mouse Position
May 5th, 2008 at 11:23pm
Print Post  
Hi Stoyo,

Still way back on v4.2.2.19341 (we will upgrade when we get a breathing point)

I am trying to get a mouse position on the chart. I understand on any MouseEventArgs, we can do a ClientToDoc to ascertain my position, but on other occasions, such as ContextMenuStrip_Opening event, I have no more knowledge (than I am aware of) of where my mouse is over the MousePosition property of the owning Form. I have tried all combinations of client, screen, point and doc methods, but none seem to get be an absolute position on the chart.

I guess I could figure the form location, the location of the chart on the form (to add complexity, it is in a docking panel).

In the past I have hacked around this quite horribly, but I want an elegant solution moving forward, if possible.

One attempt (shown below), I have inherited FlowChart to PelionFlowChart, with a few base functions I appear to be coding over and over, as well as a capturing the MouseMove event (and bubbling it up to the PelionFlowChart) to keep a 'current position' variable. The problem I have found now is that MouseMove does not fire when I am Dragging into the chart from a tree (or possibly from the chart as well, but I haven't tested that), and the x, y variables in the DragOver event appear as unhelpful as the form's Mouse Position. ([edit:] The X,Y variables are helpful, I was declaring a new Point object to store my _mousePosition into, instead of using the global scoped one Embarrassed ).
[edit:] I have a work around now, as shown below, but can you advise on a more elegant solution?

Thanks again, in advance
JC
« Last Edit: May 6th, 2008 at 12:24am by pelion »  
Back to top
 
IP Logged
 
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Re: Mouse Position
Reply #1 - May 6th, 2008 at 12:12am
Print Post  
I am currently running with the following code, it allows for a drag overs and drops to register the correct position.

I am happy to blow this whole code away for a more elegant option, but it just highlights what I am trying to achieve.

Code
Select All
    public class PelionFlowChart : MindFusion.Diagramming.WinForms.FlowChart
    {
        PointF _mousePosition;

        public new event DragEventHandler DragDrop;
        public new event DragEventHandler DragOver;
        public new event MouseEventHandler MouseMove;
        public new event EventHandler MouseLeave;

        public PelionFlowChart()
        {

            base.MouseMove += new MouseEventHandler(PelionFlowChart_MouseMove);
            base.MouseLeave += new EventHandler(PelionFlowChart_MouseLeave);
            base.DragOver += new DragEventHandler(PelionFlowChart_DragOver);
            base.DragDrop += new DragEventHandler(PelionFlowChart_DragDrop);
        }

        void PelionFlowChart_DragDrop(object sender, DragEventArgs e)
        {
            Point pScreen = new Point(e.X, e.Y);
            _mousePosition = PointToClient(pScreen);

            //bubble bubble
            if (this.DragDrop != null)
                DragDrop(sender, e);
        }

        void PelionFlowChart_DragOver(object sender, DragEventArgs e)
        {
            Point pScreen = new Point(e.X, e.Y);
            _mousePosition = PointToClient(pScreen);

            //bubble bubble
            if (this.DragOver != null)
                DragOver(sender, e);
        }

        void PelionFlowChart_MouseLeave(object sender, EventArgs e)
        {
            _mousePosition = new PointF(-1f, -1f);

            //bubble bubble
            if (this.MouseLeave != null)
                MouseLeave(sender, e);
        }

        void PelionFlowChart_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            _mousePosition = new PointF(e.X, e.Y);

            //bubble bubble
            if (this.MouseMove != null)
                MouseMove(sender, e);
        }

        #region Properties

        public PointF MousePositionOnChart { get { return ClientToDoc(new Point((int)_mousePosition.X, (int)_mousePosition.Y)); } }

        public ChartObject ObjectAtMousePosition { get { return GetObjectAt(MousePositionOnChart, false); } }

        #endregion
    } 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Mouse Position
Reply #2 - May 6th, 2008 at 8:01am
Print Post  
Hi JC,

There is the Control.MousePosition static property which returns the current mouse position in screen coordinates. You could modify your MousePositionOnChart getter to use MousePosition:

public PointF MousePositionOnChart
{
     get
     {
           return ClientToDoc(PointToClient(Control.MousePosition));
     }
}

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Re: Mouse Position
Reply #3 - May 6th, 2008 at 10:46pm
Print Post  
D'oh, of course!  Embarrassed

I've pretty much had that worked out already in the DragOver and DragDrop code, but I was evidently too deep into the captured event model to see that.

Thanks again for your help
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint