C# 如何在绘制的矩形区域上使用鼠标滚轮进行放大或缩小?
这是我用来在图片上绘制矩形的代码B:C# 如何在绘制的矩形区域上使用鼠标滚轮进行放大或缩小?,c#,winforms,C#,Winforms,这是我用来在图片上绘制矩形的代码B: private void DrawRectangle(Graphics e) { using (Pen pen = new Pen(Color.Red, 2)) { e.DrawRectangle(pen, mRect); } } private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { mRect = new Rectangl
private void DrawRectangle(Graphics e)
{
using (Pen pen = new Pen(Color.Red, 2))
{
e.DrawRectangle(pen, mRect);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
mRect = new Rectangle(e.X, e.Y, 0, 0);
pictureBox1.Invalidate();
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mRect = new Rectangle(mRect.Left, mRect.Top, e.X - mRect.Left, e.Y - mRect.Top);
pictureBox1.Invalidate();
}
}
在我画了一个矩形后,当我向上或向下移动鼠标滚轮时,它将调整图片框中图像上绘制的矩形区域的大小,我该怎么做?
不调整所有图像的大小,但仅对矩形绘制区域进行放大/缩小。熟悉鼠标滚轮事件 可以手动添加鼠标滚轮事件,如下所示,当然您可以根据需要进行设置:
this.MouseWheel += new MouseEventHandler(Form1_MouseWheel);
private void Form1_MouseWheel(object sender, MouseEventArgs e)
{
e.Delta;
// e.Delta: Represents the amount the wheel has changed. This value is positive if the mouse wheel is
// rotated in an upward direction (away from the user) or negative if the mouse wheel
// is rotated in a downward direction (toward the user).
}
您可以使用Graphics
class'ScaleTransform
缩放绘制的矩形