I am develeoping a magnifier on Mouse move control application in c#.net . I need to replace the cursor with the magnifier control(magnifier control is a picturebox). So is there anyway to accomplish this .
Asked
Active
Viewed 8,778 times
3
-
2http://www.switchonthecode.com/tutorials/csharp-tutorial-how-to-use-custom-cursors – David Brabant May 18 '12 at 06:12
-
Nice ... I am going to implement my concept with this one .. – DjMalaikallan May 18 '12 at 06:51
2 Answers
7
The example code below shows how to set a Cursor on windows form. The same approach can be used to set a Cursor for a Control too.
public class Form_With_A_Cursor_Example {
public void Shows_A_Form_With_A_Cursor_Loaded_From_A_pictureBox() {
Form frm = new Form();
PictureBox pb = new PictureBox() { Image = Image.FromFile( @"C:\Users\xxx\Pictures\someImage.bmp" ) };
frm.Cursor = new Cursor( ( (Bitmap)pb.Image ).GetHicon() );
frm.ShowDialog();
}
}

Mike Coxeter
- 589
- 1
- 6
- 18
3
First add bitmap to your project resources:
Project->projectnameProperties->Add exiting file (from menu next to "Add Resource") add your BMP
Bitmap b = new Bitmap(projectname.Properties.Resources.yourCursorName);
b.MakeTransparent(b.GetPixel(0,0));
Graphics g = Graphics.FromImage(b);
IntPtr ptr = b.GetHicon();
Cursor = new System.Windows.Forms.Cursor(ptr);
Where "projectname" is the name of your project.

AORD
- 176
- 4