Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

How to associate a tooltip to a scatterGraph annotation

I am not sure if it is the best way to do it, but I need a graph with many annotations (or it could be many "single point" XYgraph curve). Each annotations should show a string tooltip (not the X, Y coordinate). How do I create the mouse hover event for an annotations (or how do I change the "tooltip" of a "single point" XY curve)?
0 Kudos
Message 1 of 3
(6,560 Views)
One way that you could do this would be to handle the graph's PlotAreaMouseHover event. In the event handler, you can call Control.MousePosition to get the mouse cursor position in screen coordinates, pass these coordinates to the PointToClient method on the graph to convert these screen coordinates to control client coordinates, then pass these coordinates to the graph's GetAnnotationAt method. If GetAnnotationAt returns a non-null reference, the mouse is over an annotation, and you can then display a tooltip for the annotation. Here is a code snippet that demonstrates this:


private void OnGraphPlotAreaMouseHover(object sender, EventArgs e)
{
Point mousePoint = graph.PointToClient(Control.MousePosition);
XYAnnotation annotation = graph.GetAnnotationAt(mousePoint.X, mousePoint.Y);

if (annotation != null)
{
// Display annotation tooltip here.
}
}


This is a good feature idea and I will file a suggestion to add tooltip support to annotations in a future version of Measurement Studio.

- Elton
0 Kudos
Message 2 of 3
(6,551 Views)
Hello Elton

I had to make some changes for VB, but because I don't need the caption and arrow things from the annotations, I finaly got something, thanks to you.

Here my code (where scgJames is the Graph, and JamesXpas is the Xaxis)

Private Sub scgJames_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles scgJames.Click
Dim ThisAnnotation As XYAnnotation
Dim mousePoint As Point
mousePoint = scgJames.PointToClient(Control.MousePosition)
ThisAnnotation = scgJames.GetAnnotationAt(mousePoint.X, mousePoint.Y)
Try
'if the axis are not the same, there will be an error and it won't be processed
If ThisAnnotation.XAxis Is JamesXpas Then
MessageBox.Show(ThisAnnotation.Caption)
End If
Catch ex As Exception
End Try

End Sub

when I create the annotations, I make sure to set these values, so the caption from each annotations are not visible, but the annotation itself is visible:
myAnnotationPoint.ArrowVisible = False
myAnnotationPoint.Caption = "whatever I want to put"
myAnnotationPoint.CaptionAlignment = New NationalInstruments.UI.AnnotationCaptionAlignment(NationalInstruments.UI.BoundsAlignment.BottomLeft, 0.0!, 0.0!)
myAnnotationPoint.CaptionFont = New System.Drawing.Font("Microsoft Sans Serif", 1.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
myAnnotationPoint.CaptionForeColor = scgJames.ForeColor



with the code you gave me, if I click on the annotation I got a message box showing the caption from the annotation!


Thanks again

There are so much things to learn!
Lew
0 Kudos
Message 3 of 3
(6,534 Views)