开发者

Crosshair cursor with additional lines in C#

how to make a crosshair cursor with help lines like this on screenshots:

Crosshair cursor with additional lines in C#

I know how to make crosshire cursor:

 this.Cursor = System开发者_如何学JAVA.Windows.Forms.Cursors.Cross;

can be also something like that:

Crosshair cursor with additional lines in C#

like in CAD software.


This is the code I use. x and y are the dimensions. In my case I can have some text on the cursor and this is name. If you want dots or dashes then you need to do that with the pen.

   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;
        }


Just create two label box as lab_X_Axis and lab_Y_Axis. In chart mousemove function code as shown below..

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜