How can i replace cursor with bitmap in winform

前端 未结 2 1858
有刺的猬
有刺的猬 2020-12-11 21:32

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

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 22:12

    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();
        }
    }
    

提交回复
热议问题