In that cases, the cursor should be changed, because arrow cursor will not be a comfortable one to pick color. Normally cursor values resides in registry.
Registry Key : HKEY_CURRENT_USER\Control Panel\Cursors
Changing the values here will change the cursor, but your system needs a reboot to take effect (I can understand, none of the developers will accept this). To avoid that and make your app. taking immediate effect, you need to invoke a pinvoke call.
The following method will refresh the cursor values,
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
Iterate through registry values and change the cursor path.
private void ChangeCursor()
{
RegistryKey pRegKey = Registry.CurrentUser;
pRegKey = pRegKey.OpenSubKey(@"Control Panel\Cursors");
paths.Clear();
foreach (var key in pRegKey.GetValueNames())
{
Object _key = pRegKey.GetValue(key);
//Take a backup.paths.Add(key, _key.ToString()); Object val = Registry.GetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors", key, null); Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors", key, "foo.cur"); } SystemParametersInfo(InteropHelper.SPI_SETCURSORS, 0, null, InteropHelper.SPIF_UPDATEINIFILE | InteropHelper.SPIF_SENDCHANGE); }
Make sure you store the registry values before change it, so that you can restore the cursor to the default values.
private void ResetCursorToDefault()
{RegistryKey pRegKey = Registry.CurrentUser;
pRegKey = pRegKey.OpenSubKey(@"Control Panel\Cursors");
foreach (string key in paths.Keys)
{
string path = paths[key];
Registry.SetValue(@"HKEY_CURRENT_USER\Control Panel\Cursors", key, path);
}
InteropHelper.SystemParametersInfo(InteropHelper.SPI_SETCURSORS, 0, null, InteropHelper.SPIF_UPDATEINIFILE | InteropHelper.SPIF_SENDCHANGE);
}The InteropHelper class has been posted in this article.
You could find the InteropHelper class implementation in below article,
http://wpfplayground.blogspot.in/2012/04/capture-screenshot-in-wpf.html
Thanks,
Jawahar
Hey ! Nice post! I just wonder where that “InteropHelper” comes from ? Haven't found it in WPF name spaces.