Torna al Thread
void DrawPanel_MouseDown(object sender, MouseEventArgs e)
{
xStart =e.X;
yStart = e.Y;
xEnd = -1;
yEnd = -1;
pressed = true;
}
void DrawPanel_MouseEnter(object sender, EventArgs e)
{
Cursor = Cursors.Cross;
}
void DrawPanel_Paint(object sender, PaintEventArgs e)
{
foreach (Rectangle r in rectangles)
{
graph.DrawRectangle(penna, r); //la penna colora con il colore impostato nella proprietà Forecolor del Panel
}
}
public void Cancel()
{
browser.Visible = true;
}
void DrawPanel_MouseUp(object sender, MouseEventArgs e)
{
if (pressed)
{
xEnd=e.X;
yEnd=e.Y;
int width = xEnd - xStart;
int height = yEnd - xStart;
Rectangle r = new Rectangle(xStart, yStart, width, height);
graph.DrawRectangle(penna, r);
rectangles.Add(r);
}
pressed = false;
}
void DrawPanel_MouseMove(object sender, MouseEventArgs e)
{
if (pressed)
{
//devo cancellare il disegno precedente:
int width = xEnd - xStart;
int height = yEnd - xStart;
graph.DrawRectangle(cancellino, xStart, yStart, width, height); //il cancellino e è un oggetto di tipo Pen che colora con il colore di //sfondo del Panel
//ora aggiorno le coordinate per disegnare il nuovo rettangolo:
xEnd = e.X;
yEnd = e.Y;
width = xEnd - xStart;
height = yEnd - xStart;
graph.DrawRectangle(penna, xStart, yStart, width, height);
}
}
}
}