2011-08-24 111 views
1

如何使十字光标的帮助线这样的截图:十字光标在C#中其他行

enter image description here

我知道如何使crosshire光标:

this.Cursor = System.Windows.Forms.Cursors.Cross; 

可还有类似的东西:

enter image description here

喜欢用CAD软件。

+1

[使用自定义光标的WinForms](http://stackoverflow.com/questions/2797084/using-custom-cursor-winforms)的可能重复 –

+0

需要先制作一个.cur文件。然后你可以将它嵌入到程序集中。如上所述。 – PythEch

回答

3

这是我使用的代码。 x和y是尺寸。在我的情况下,我可以在光标上有一些文本,这是名称。如果你想要点或破折号,那么你需要用笔做到这一点。

private Cursor crossCursor(Pen pen, Brush brush, string name, int x, int y) { 
      var pic = new Bitmap(x, y); 
      Graphics gr = Graphics.FromImage(pic); 

      var pathX = new GraphicsPath(); 
      var pathY = new GraphicsPath(); 
      pathX.AddLine(0, y/2, x, y/2); 
      pathY.AddLine(x/2, 0, x/2, y); 
      gr.DrawPath(pen, pathX); 
      gr.DrawPath(pen, pathY); 
      gr.DrawString(name, Font, brush, x/2 + 5, y - 35); 

      IntPtr ptr = pic.GetHicon(); 
      var c = new Cursor(ptr); 
      return c; 
     } 
+0

干得好! ;)但是如果我是他/她,我会使用.cur(游标)文件。 – PythEch

+0

谢谢!很公平。我这样做,因为名称值可以改变。我有他们不同的大小,也有另一个超载,将放在眼球上的靶心 – ScruffyDuck

+0

我明白了,无论如何这是一个很好的代码:) – PythEch

0

只需创建两个标签框,lab_X_Axislab_Y_Axis。 在图表鼠标移动功能代码如下所示..

private void chart1_MouseMove(object sender, MouseEventArgs e) 
{ 
    lab_X_Axis.Location = new Point((e.X), 21); 
    lab_Y_Axis.Location = new Point(76, e.Y); 
} 

private void Form1_Load(object sender, EventArgs e) 
{ 
    lab_X_Axis.AutoSize = false; 
    lab_Y_Axis.AutoSize = false; 
    lab_X_Axis.Text=""; 
    lab_Y_Axis.Text=""; 
    lab_X_Axes.Size = new Size(1, 300); 
    lab_Y_Axes.Size = new Size(300, 1); 
} 
+0

请不要发布重复内容,并且请仔细关注您正在回答的问题。 –