I could successfully change the mouse cursor in a vanilla C# app as explained here. I am using a C# app which uses Zedgraph dll for plotting charts. While the mouse pointer is on top of the chart it turns in to a crosswire. I need to change the cursor in to a another image. However i am unable to do this using the earlier code sample. I suspect this is because Zedgraph library already overloads the cursor change events. zgObj is the Zedgraph object in the code given below. Any ideas?
void ToggleCursor()
{
Bitmap bitmap = new Bitmap(@"C:\Documents and Settings\Martin\My Documents\My Pictures\line.bmp");
zgObj.Cursor = XCursor.CreateCursor(bitmap, 0, 0);
bitmap.Dispose();
}
public class XCursor : Form
{
[DllImport("user32.dll")]
public static extern IntPtr CreateIconIndirect(ref IconInfo icon);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetIconInfo(IntPtr hIcon, ref IconInfo pIconInfo);
public static Cursor CreateCursor(Bitmap bmp, int xHotSpot, int yHotSpot)
{
IntPtr ptr = bmp.GetHicon();
IconInfo tmp = new IconInfo();
GetIconInfo(ptr, ref tmp);
tmp.xHotspot = xHotSpot;
tmp.yHotspot = yHotSpot;
tmp.fIcon = false;
ptr = CreateIconIndirect(ref tmp);
return new Cursor(ptr);
}
}
public struct IconInfo
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}