Dundas Chart for Windows Forms
SetCursorPixelPosition Method
See Also  Example Send comments on this topic.
DundasWinChart Assembly > Dundas.Charting.WinControl Namespace > Cursor Class : SetCursorPixelPosition Method


coord
A PointF structure that determines the point where the cursor will be drawn.
New cursor position as pixel coordinates.
roundToBoundary
If true then the cursor will be drawn along the nearest chart area boundary if the specified position does not fall within a ChartArea object.
Indicates that coordinates must be rounded to area plotting boundary.
Call this method to display a cursor at the specified position.  Measured in pixels.
Sets new cursor position.

Syntax

Visual Basic (Declaration)  
Public Sub SetCursorPixelPosition( _
   ByVal coord As PointF, _
   ByVal roundToBoundary As Boolean _
) 
Visual Basic (Usage) Copy Code
Dim instance As Cursor
Dim coord As PointF
Dim roundToBoundary As Boolean
 
instance.SetCursorPixelPosition(coord, roundToBoundary)
C#  
public void SetCursorPixelPosition( 
   PointF coord,
   bool roundToBoundary
)

Parameters

coord
A PointF structure that determines the point where the cursor will be drawn.
New cursor position as pixel coordinates.
roundToBoundary
If true then the cursor will be drawn along the nearest chart area boundary if the specified position does not fall within a ChartArea object.
Indicates that coordinates must be rounded to area plotting boundary.

Example

C# Copy Code
using Dundas.Charting.WinControl;
...

// Flag For range selection operation
Public bool bSelecting;

Private
void chart1_MouseDown(Object sender, System.Windows.Forms.MouseEventArgs e){
// We Set selection flad To True, And Set the start position of the selected range, As
//   well As setting the position of the cursors

   
If(e.Button == MouseButtons.Right)
   {
   
       bSelecting = True;
       
//create New point, using mouse click coordinates
       
PointF myPoint = New PointF(e.X, e.Y);
       
// Set the Y And X axes cursor positions, As well As the beginning of the range selection
       
chart1.ChartAreas["Default"].CursorX.SetCursorPixelPosition(myPoint, False);
       chart1.ChartAreas[
"Default"].CursorY.SetCursorPixelPosition(myPoint, False);
       chart1.ChartAreas[
"Default"].CursorX.SetSelectionPixelPosition(myPoint, PointF.Empty, False);
       chart1.ChartAreas[
"Default"].CursorY.SetSelectionPixelPosition(myPoint, PointF.Empty, False);
   }
}

Private
void chart1_MouseMove(Object sender, System.Windows.Forms.MouseEventArgs e)
{

   If(e.Button == MouseButtons.Right)
   {
   
       
//create New point, using mouse click coordinates
       
       
PointF myPoint = New PointF(e.X, e.Y);
       
// Set the Y And X axes cursor positions, As well As the end of the selected range
       
chart1.ChartAreas["Default"].CursorX.SetCursorPixelPosition(myPoint, False);
       chart1.ChartAreas[
"Default"].CursorY.SetCursorPixelPosition(myPoint, False);
       chart1.ChartAreas[
"Default"].CursorX.SetSelectionPixelPosition(PointF.Empty, myPoint, False);
       chart1.ChartAreas[
"Default"].CursorY.SetSelectionPixelPosition(PointF.Empty, myPoint, False);
   }
}

Private
void chart1_MouseUp(Object sender, System.Windows.Forms.MouseEventArgs e)
{
   bSelecting = False;
}
Visual Basic Copy Code
Imports Dundas.Charting.WinControl

...

'flag for range selection operation
Dim bSelecting As Boolean

Private Sub chart1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles chart1.MouseDown
' We set selection flag to TRUE, and set the start position of the selected range, as
' well as setting the position of the cursors

If e.Button = MouseButtons.Right Then

bSelecting = True
'create new point, using mouse click coordinates
Dim myPoint As New PointF(e.X, e.Y)
' Set the Y and X axes cursor positions, as well as the beginning of the range selection
chart1.ChartAreas("Default").CursorX.SetCursorPixelPosition(myPoint, False)
chart1.ChartAreas("Default").CursorY.SetCursorPixelPosition(myPoint, False)
chart1.ChartAreas("Default").CursorX.SetSelectionPixelPosition(myPoint, myPoint.Empty, False)
chart1.ChartAreas("Default").CursorY.SetSelectionPixelPosition(myPoint, myPoint.Empty, False)

End If

End Sub

Private Sub chart1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles chart1.MouseMove
'Set the Y and X axes cursor positions, as well as the beginning of the range selection

If e.Button = MouseButtons.Right Then

'create new point, using mouse click coordinates
Dim myPoint As New PointF(e.X, e.Y)
' Set the Y and X axes cursor positions, as well as the beginning of the range selection
chart1.ChartAreas("Default").CursorX.SetCursorPixelPosition(myPoint, False)
chart1.ChartAreas("Default").CursorY.SetCursorPixelPosition(myPoint, False)
chart1.ChartAreas("Default").CursorX.SetSelectionPixelPosition(myPoint.Empty, myPoint, False)
chart1.ChartAreas("Default").CursorY.SetSelectionPixelPosition(myPoint.Empty, myPoint, False)

End If

End Sub

Private Sub chart1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles chart1.MouseUp
'just reset flag

bSelecting = False

End Sub

Remarks

This method displays a cursor at the specified location, and is measured in pixels.  Note that the point 0,0 is the top-left corner of the entire chart image, and NOT the relevant chart area.

If the roundToBoundary parameter is FALSE then the cursor will not be drawn if the specified coordinate is located outside of a chart area.  However, if roundToBoundary is TRUE then the cursor will be drawn along the nearest chart area boundary if the point is not inside a chart area.

When using this method for the horizontal cursor the Point.X parameter value affects whether or not the cursor is actually drawn, depending on whether the point occurs within a chart area as well as the roundToBoundary parameter setting.  The PointF.Y parameter is used for the pixel value where the cursor will be drawn.  The same situation holds true for the vertical cursor, but vice-versa.

SetCursorPixelPosition can be very useful if a cursor position is being set inside some sort of event caused by user-interaction.  For example, if the Mouse_Down event is being used to implement cursors when the middle mouse button is clicked SetCursorPixelPosition can be used to set the cursor position.  The X and Y coordinates of the mouse click can be obtained from the event arguments, and like this method will use pixels, with a 0,0 coordinate at the top-left corner of the chart image.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2009 All Rights Reserved.