Jump to content
Software FX Community

MouseMove event args not returning point when mouse is over the label


Mike O'Neal
 Share

Recommended Posts

I am trying to set up a Gantt style chart where the point label from the data appears to the left of the chart. Some of the names are really long and I need to truncate them for display to prevent it from pushing the chart size down to nothing. I am trying to adjust the tooltip over the label on the x axis (now on the left in the Gannt chart) to show the full value by using the MouseMove event to determine I am over the axis area and the GetTip event to adjust the label to the full value. When I mouse over the label, the point is always returned as -1 instead of the correct point in both events. However, when I mouse over the datagrid column header for the same thing, both events return the correct point value.

How do I determine which point it is so I can go get the correct value from my datasource?

Link to comment
Share on other sites

For performance reasons, the HitTest is not done during a MouseMove, therefore Series and Point will always be -1 during this event.

What you should do is simply store X and Y in the MouseMove event and then, during GetTip call HitTest with these values to determine the closest label. The following code snippet illustrates how to do this:

private int m_lastMouseX,m_lastMouseY;private void chart1_MouseMove (object sender,HitTestEventArgs e)

{

  m_lastMouseX = e.X;

  m_lastMouseY = e.Y;

}

private void chart1_GetTip (object sender,GetTipEventArgs e) {

  HitTestEventArgs a = chart1.HitTest(m_lastMouseX,m_lastMouseY);  if ((a.HitType == HitType.Axis) && (a.Object == chart1.AxisX)) {

  int closestLabel = (int) Math.Round(a.Value);   e.Text = "Long Label " + closestLabel.ToString();

  }

}

Link to comment
Share on other sites

Thanks!!!

I was able to get what I needed with that. The piece of info I didn't understand was that the Value is returning a number that is the proportional distance up the x axis.

Some additional info: 

Because I needed to determine which point I was on and refer back to the datasource to get the correct value, I used the following code in the GetTip() event to fix the tooltip only if I was on a point label in the axis.

private void chart1_GetTip(object sender, GetTipEventArgs e)

{

if (e.Object == chart1.AxisX)

{

  if (e.Text.Length > 0)

  {

HitTestEventArgs e1 = chart1.HitTest(m_lastMouseX , m_lastMouseY);

int currentPoint = (int)Math.Floor(e1.Value); if (currentPoint < ((DataView)chart1.DataSource).Count)

{

  e.Text = (string)((DataView)chart1.DataSource)[currentPoint]["Long Field Name"];

}

  }

}

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...