c# - 如何在整个 Windows 操作系统中更改光标(图像)

标签 c# .net

我需要在所有窗口中更改光标,而不仅仅是在应用程序中,我试过这个:

this.Cursor = Cursors.WaitCursor;

还有这个:

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;

但它只会更改我的应用程序中的光标。

有什么想法吗?

最佳答案

假设您有自己的游标文件 (.cur) 可以应用,您可以破解它。

首先,您必须更改注册表中的默认箭头光标,然后您需要调用一些 P-Invoke 以允许操作系统更新当前系统参数,以便光标实际更改。

类似的东西:

    private void ChangeCursor(string curFile)
    {
        Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors\", "Arrow", curFile);
        SystemParametersInfo(SPI_SETCURSORS, 0, null, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); 
    }

    const int SPI_SETCURSORS = 0x0057; 
    const int SPIF_UPDATEINIFILE = 0x01; 
    const int SPIF_SENDCHANGE = 0x02; 

    [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
    public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint? pvParam, uint fWinIni);

用法:

 ChangeCursor(@"C:\MyCursor.cur");

关于c# - 如何在整个 Windows 操作系统中更改光标(图像),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15016414/

相关文章:

.net - 更改面板的 CSSclass

c# - 为什么隐式使用 ToString() 不会导致异常?

.net - 的意义是什么 !在代码中?

c# - 获取 "This method or property cannot be called on Null values"错误

c# - Jenkins 未使用新的 MSBuild 恢复目标恢复 NuGet 包

c# - 使用 C# 执行忽略 xsl :output 的 xslt 转换

c# - 在 python 中锁定字典

c# - 如何将 .spritefont 制作成 Monogame?

mysql - 如何使用 VB.Net 中已定义的列填充 datagridview

c# - 如何防止窗口在 .NET 中显示?