我有一段代码在 Mouse_Up 时在 C# Windows 窗体上执行。它基本上会放大渲染图像,并在每次绘制橡皮筋时不断放大。我想通过添加一个复选框(我已经完成)来扭转这一点,如果勾选了该复选框,请根据橡皮筋的绘图从当前视图进行缩小。我认为这就像使用相反的操作数一样简单,即“+”而不是“-”,但它不会起作用。我已经在下面发布了事件代码。那里有一个条件 IF 用于更改复选框状态。第一部分可以很好地放大。ELSE IF 之后的部分不允许我缩小 - 因此我只是在那里留下了重复的代码供某人查看。谢谢
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
if (checkBox1.Checked == false)
{
int z, w;
this.Cursor = Cursors.Arrow;
// Set internal flag to know we no longer "have the mouse".
weHaveMouse = false;
// If we have drawn previously, draw again in that spot
// to remove the lines.
if (ptLast.X != -1)
{
toolStripStatusLabel1.Text = "Please click and drag to zoom into the Fractal";
Point ptCurrent = new Point(e.X, e.Y);
MyDrawReversibleRectangle(ptOriginal, ptLast);
}
// Set flags to know that there is no "previous" line to reverse.
ptLast.X = -1;
ptLast.Y = -1;
ptOriginal.X = -1;
ptOriginal.Y = -1;
//e.consume();
if (action)
{
xe = e.X;
ye = e.Y;
if (xs > xe)
{
z = xs;
xs = xe;
xe = z;
}
if (ys > ye)
{
z = ys;
ys = ye;
ye = z;
}
w = (xe - xs);
z = (ye - ys);
if ((w < 2) && (z < 2)) initvalues();
else
{
if (((float)w > (float)z * xy)) ye = (int)((float)ys + (float)w / xy);
else xe = (int)((float)xs + (float)z * xy);
xende = xstart + xzoom * (double)xe;
yende = ystart + yzoom * (double)ye;
xstart += xzoom * (double)xs;
ystart += yzoom * (double)ys;
}
xzoom = (xende - xstart) /(double)x1;
yzoom = (yende - ystart) / (double)y1;
mandelbrot();
rectangle = false;
//Refresh();
}
}
else if (checkBox1.Checked == true)
{
int z, w;
this.Cursor = Cursors.Arrow;
// Set internal flag to know we no longer "have the mouse".
weHaveMouse = false;
// If we have drawn previously, draw again in that spot
// to remove the lines.
if (ptLast.X != -1)
{
toolStripStatusLabel1.Text = "Please click and drag to zoom into the Fractal";
Point ptCurrent = new Point(e.X, e.Y);
MyDrawReversibleRectangle(ptOriginal, ptLast);
}
// Set flags to know that there is no "previous" line to reverse.
ptLast.X = -1;
ptLast.Y = -1;
ptOriginal.X = -1;
ptOriginal.Y = -1;
//e.consume();
if (action)
{
xe = e.X;
ye = e.Y;
if (xs > xe)
{
z = xs;
xs = xe;
xe = z;
}
if (ys > ye)
{
z = ys;
ys = ye;
ye = z;
}
w = (xe - xs);
z = (ye - ys);
if ((w < 2) && (z < 2)) initvalues();
else
{
if (((float)w > (float)z * xy)) ye = (int)((float)ys + (float)w / xy);
else xe = (int)((float)xs + (float)z * xy);
xende = xstart + xzoom * (double)xe;
yende = ystart + yzoom * (double)ye;
xstart += xzoom * (double)xs;
ystart += yzoom * (double)ys;
}
xzoom = (xende - xstart) / (double)x1;
yzoom = (yende - ystart) / (double)y1;
mandelbrot();
rectangle = false;
//Refresh();
}
}
}