我需要在所有窗口中更改光标,而不仅仅是在应用程序中,我试过这个:
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/