这个代码我用来在pictureBox1上绘制一个矩形:
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();
}
}
当我向上或向下移动鼠标滚轮时绘制一个矩形之后如何制作它,它会调整pictureBox1中iamge上绘制的矩形区域的大小? 不调整所有图像的大小,只对矩形绘制区域进行放大/缩小。
答案 0 :(得分:0)
熟悉MouseWheel事件。
答案 1 :(得分:0)
可以手动添加鼠标滚轮事件,如下所示,当然您可以根据需要进行设置:
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
类“ScaleTransform
缩放绘制的矩形。