Hi I've been given the task of converting a java application to a c# windows form application. The program displays a Mandelbrot which then allows the user to zoom into. I've managed to display the Mandelbrot and even zoom. However when dragging a box to zoom, the box its self doesn't show, meaning the user cannot see what area they will be zooming into.
I believe I need to call the update function which draws the rectangle as I drag Here is the code that I believe is relevant.
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
//e.consume();
if (action)
{
xs = e.X;
ys = e.Y;
}
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
int z, w;
//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();
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
//e.consume();
if (action)
{
xe = e.X;
ye = e.Y;
rectangle = true;
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g1 = e.Graphics;
g1.DrawImage(bitmap, 0, 0, x1, y1);
g1.Dispose();
}
public void paint(Graphics g1)
{
update(g1);
}
public void update(Graphics g1)
{
Pen pen = new Pen(Color.White);
g1.DrawImage(bitmap, 0, 0, x1, y1);
if (rectangle)
{
if (xs < xe)
{
if (ys < ye) g1.DrawRectangle(pen, xs, ys, (xe - xs), (ye - ys));
else g1.DrawRectangle(pen, xs, ye, (xe - xs), (ys - ye));
}
else
{
if (ys < ye) g1.DrawRectangle(pen, xe, ys, (xs - xe), (ye - ys));
else g1.DrawRectangle(pen, xe, ye, (xs - xe), (ys - ye));
}
pen.Dispose();
}
}