privatevoid pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
//移动处理
if (!isLeftCtrlKeyDown)
{
offset.Width += e.X - mousePressPoint.X;
offset.Height += e.Y - mousePressPoint.Y;
mousePressPoint = e.Location;
Bitmap newbmp =new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
Graphics g = Graphics.FromImage(newbmp);
//重绘一小段图片
g.DrawImage(bmp, new Rectangle(0, 0, this.ClientSize.Width, this.ClientSize.Height),
-offset.Width, -offset.Height, this.ClientSize.Width, this.ClientSize.Height, GraphicsUnit.Pixel);
pictureBox1.Image = newbmp;
pictureBox1.Refresh();
}
else
{
//放大缩小处理
int width = bmp.Width + pictureBox1.Location.X + e.X - mousePressPoint.X;
int height = bmp.Height + pictureBox1.Location.Y + e.Y - mousePressPoint.Y;
if (width >0&& height >0)
{
bmp =new Bitmap(bmp, new Size(width, height));
pictureBox1.Image = bmp;
pictureBox1.Refresh();
}
}
}
}
浙公网安备 33010602011771号