更改光标跨越,而形式是开放的(片段工具) [英] Change cursor to cross while form is open (snippet tool)

查看:79
本文介绍了更改光标跨越,而形式是开放的(片段工具)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现像Gyazo片段工具,它的屏幕截图软件。该计划开始(显示在屏幕上什么都没有,比光标变化等),用户点击到A点,然后拖拽到B点(绘制一个透明的矩形),释放鼠标,然后截图被保存,程序关闭。

I am trying to implement a software like "Gyazo", a snippet tool that takes a screenshot. The program begins (nothing appears on the screen, other than the cursor changing), the user clicks to point A, then drags to point B (drawing a transparent rectangle), releases the mouse, then the screenshot gets saved and the program closes.

我得出的方式,透明矩形,是我重新大小和重新定位用30%的透明度的形式。所以光标从来没有在表格上!为了改变光标,因为它的形式之外,我尝试使用:

The way I draw that transparent rectangle, is that I re-size and re-position a form with a 30% transparency. So the cursor is never on the form! In order to change the cursor, since it is outside of the form, I tried using:

[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
private int CROSS = 32515;
private const uint NORMAL = 32512;

//and then calling
SetSystemCursor(LoadCursor(IntPtr.Zero, CROSS), NORMAL);



我有这段代码的问题是,它真的是马车。当窗体关闭时,光标不会更改恢复正常。我不知道如何正确地恢复光标。此外,恢复光标的当表单从任务管理器关闭的将是不可能的,对不对?

The problem I had with this code is that it is really buggy. When the form closes, the cursor doesn't change back to normal. I don't know how to revert the cursor properly. Also, reverting the cursor when the form is closed from the task manager will be impossible, correct ?

您有什么建议其他的方式来改变光标在这种情况下穿越?

What other way would you suggest to change the cursor to cross in this case ?

修改只是为了澄清,因为我试图问其之前被标记为的这个问题,我删除了它,我所要做的是相似的,但有很多不同的,因为在这个问题提供了答案,在答案提供的解决方案,就是让全屏无国界形式,设置在桌面上作为形式的背景的屏幕截图,然后从该剪裁矩形。首先,该解决方案冻结在屏幕上,因为所有你看到你的桌面上的照片,而在裁剪发生,其次,它几乎是不可能处理多显示器设置的方式。再加上它的额外和不必要的工作。

Just to clarify, because I tried asking a similar question before which was marked as duplicate of this question and I deleted it, what I am trying to do is similar, but a lot different, because in the answer provided in that question, the solution provided in the answers, is to make a full-screen borderless form, set a screenshot of the desktop as the background of that form, and then crop a rectangle from that. Firstly, that solution "freezes" the screen, since all you see a photo of your desktop while the cropping takes place, and secondly, it is near impossible to handle multi-monitor setups that way. Plus it does extra and unnecessary work.

推荐答案

尝试把这个在你的Program.cs文件

Try putting this on your Program.cs file

static class Program
{
    [DllImport("user32.dll")]
    static extern bool SetSystemCursor(IntPtr hcur, uint id);
    [DllImport("user32.dll")]
    static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32
    uiParam, String pvParam, UInt32 fWinIni);

    private static uint CROSS = 32515;
    private static uint NORMAL = 32512;
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        SetSystemCursor(LoadCursor(IntPtr.Zero, (int)NORMAL), CROSS);
        //Also other pointers to CROSS if you want
        Application.Run(new Form1());
        SystemParametersInfo(0x0057, 0, null, 0);
    }
}

这会使其恢复到正常每当应用程序结束或崩溃..

this will revert it back to normal whenever the application ends or crashes..

于是想从正常变化的交叉,你可以改变你想要箭头

So like changing from Normal to Cross, you can change whatever cursor you want to Arrow

当你停止应用程序(按Ctrl + F5)它不会工作,因为这将跳过所有行。但是,将发布申请后完全正常工作。

It won't work when you stop the application (Ctrl+F5), because that will skip all the lines. But will work completely after publishing the application.

这篇关于更改光标跨越,而形式是开放的(片段工具)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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