C# 中带有附加行的十字光标 [英] Crosshair cursor with additional lines in C#

查看:35
本文介绍了C# 中带有附加行的十字光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在屏幕截图上使用这样的帮助行制作十字光标:

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

我知道如何制作交叉租用光标:

I know how to make crosshire cursor:

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

也可以是这样的:

就像在 CAD 软件中一样.

like in CAD software.

推荐答案

这是我使用的代码.x 和 y 是维度.就我而言,我可以在光标上放置一些文本,这就是名称.如果你想要点或破折号,那么你需要用笔来做.

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

这篇关于C# 中带有附加行的十字光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆