界面:
核心代码:
Cursor myCursor = new Cursor(@"C:\WINDOWS\Cursors\aero_cross.cur"); //自定义鼠标
Image myImage;
//选择图片
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = "*.jpg,*.jpeg,*.bmp,*.gif,*.ico,*.png,*.tif,*.wmf|*.jpg;*.jpeg;*.bmp;*.gif;*.ico;*.png;*.tif;*.wmf";
openFileDialog1.ShowDialog();
myImage = System.Drawing.Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = myImage;
pictureBox1.Height = myImage.Height;
pictureBox1.Width = myImage.Width;
}
//鼠标经过的地方放大
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
try
{
Cursor.Current = myCursor;
Graphics graphics = pictureBox1.CreateGraphics();
Rectangle sourceRectangle = new Rectangle(e.X - 10, e.Y - 10, 20, 20); //要放大的区域
Rectangle destRectangle = new Rectangle(e.X - 20, e.Y - 20, 40, 40);
graphics.DrawImage(myImage, destRectangle, sourceRectangle, GraphicsUnit.Pixel);
}
catch
{ }
}