Hi; In need of some guidance. I have a form which has a list box upon it. with items in it. These items are dragged out of this and a custom control is added to the form. All this works fine. However a new requirement is that there should be a ghost copy to follow the mouse when this is conducted.
I have managed to create a new Cursor which is generated dynamically by creating a bitmap of the control, and then adding this through the CustomCursor.CreatCursor() method. When the item is initially clicked in the lstJobs list box the cursor changes.
This is all fine until....
You drag the item away from this list box on to the rest of the form; which has worked till this reguirement through:
lstjobs.DoDragDrop(JobID,DragDropEffects.All)
to set the cursor I am using the following:
RectangleF RecF = new RectangleF();
RecF.Height = RecF.Height + OC.Height;
Bitmap memoryImage = new Bitmap(OC.Width, OC.Height);
OC.DrawToBitmap(memoryImage, new Rectangle(new Point(), OC.Size));
Graphics G = Graphics.FromImage(memoryImage);
using (Font f = new Font(FontFamily.GenericSansSerif, 10))
G.DrawString("Drop on form", f, Brushes.Green, 0, 0);
Cursor.Current = CustomCursor.CreateCursor(memoryImage, 3, 3);
this.Cursor = CustomCursor.CreateCursor(memoryImage, 3, 3);
memoryImage.Dispose();
Where the class CustomCursor is generated as follows:
public struct IconInfo
{
public bool fIcon;
public int xHotspot;
public int yHotspot;
public IntPtr hbmMask;
public IntPtr hbmColor;
}
public static class CustomCursor
{
[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)
{
IconInfo tmp = new IconInfo();
GetIconInfo(bmp.GetHicon(), ref tmp);
tmp.xHotspot = xHotSpot;
tmp.yHotspot = yHotSpot;
tmp.fIcon = false;
return new Cursor(CreateIconIndirect(ref tmp));
}
}
So running with out break points makes it appear that nothing changes... how ever when you had breakpoints in it appears that when Events are firing such as drag enter, drag over then the cursor is getting reset. any ideas?
Thanks in advance.