未连接鼠标时以编程方式显示鼠标光标

时间:2017-10-09 07:55:26

标签: c# wpf windows xaml user-interface

我正在尝试构建a touchless interface using C#。我使用此界面来控制其他程序或Windows UI元素。为此,我主要使用user32.dll来执行鼠标控制操作。

当我尝试使用the touchless interface时,当没有鼠标连接到电脑时,我仍然可以移动鼠标光标,但它是不可见的。

我知道通过使用鼠标键选项,可以使鼠标光标可见。但是,我更愿意在代码中以编程方式使其可见。

可以使用.Net

使光标可见

3 个答案:

答案 0 :(得分:0)

您可以使用user32.dll。

internal static class WinCursors
{
    [DllImport("user32.dll")]
    private static extern int ShowCursor(bool bShow);


    internal static void ShowCursor()
    {
        while (ShowCursor(true) < 0)
        {
             ShowCursor(true);
        }
    }

    internal static void HideCursor()
    {
        while (ShowCursor(false) >= 0) 
        {
             ShowCursor(false);
        }
    }
}

答案 1 :(得分:-1)

您是在谈论自己的申请表格还是想与其他申请表进行互动?

如果它是你自己的,我认为Windows.Forms命名空间下的这种方法会阻止你: https://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.hide(v=vs.110).aspx

如果不是我害怕你不能,那么做C#并不是很好的做Windows边界的东西,当谈到Windows shell界面时,最好的路线几乎总是通过user32.dll,就像这里: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648396(v=vs.85).aspx

我个人不喜欢将外来DLL导入C#管理系统,它听起来不够好,我会去C / C ++,但是如果它太多了复杂,我认为,一个很好的选择是golang,它有一个更丰富的标准库,它比C / C ++更容易处理,但是,当然,这取决于你的需求。

干杯

答案 2 :(得分:-2)

这个(或某些变体)会让你成为一个可见光标吗?

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