1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| //**************************************************************************************************
void pbDrawRectangle(int X,int Y)
{
pb_cont.Refresh();
int dX = Math.Abs(X-pRef.X);
int dY = Math.Abs(Y-pRef.Y);
int Z = Math.Max(dX, dY);
dX = Z;
dY = Z;
int rX = pRef.X;
int rY = pRef.Y;
if (X - pRef.X < 0) rX = X;
if (Y - pRef.Y < 0) rY = Y;
Graphics graphics = pb_cont.CreateGraphics();
graphics.DrawRectangle(Pens.Black, rX, rY, dX, dY);
}
//**********************************************************************************************
private void pb_cont_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
pRef.X = e.X;
pRef.Y = e.Y;
}
}
private void pb_cont_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
pbDrawRectangle(e.X, e.Y);
return;
}
}
private void pb_cont_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
pbZoom(e.X, e.Y);
return;
}
} |
Partager