2011-08-24 107 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

請不要發佈重複內容,並且請仔細關注您正在回答的問題。 –