Comme ça par exemple..
public partial class Form1 : Form
{
private PictureBox pb = null;
private Point start = Point.Empty;
private Point end = Point.Empty;
private Rectangle frame = Rectangle.Empty;
private bool draw = false;
public Form1( )
{
InitializeComponent( );
pb = new PictureBox( );
pb.Parent = this;
pb.Dock = DockStyle.Fill;
pb.SizeMode = PictureBoxSizeMode.StretchImage;
pb.Image = this.Icon.ToBitmap( ); // pour l'exemple.
pb.MouseDown += delegate( object sd, MouseEventArgs args )
{
if ( args.Button == MouseButtons.Left )
{
draw = true;
start = pb.PointToScreen( args.Location );
}
};
pb.MouseUp += delegate( object sd, MouseEventArgs args )
{
draw = false;
};
pb.MouseMove += delegate( object sd, MouseEventArgs args )
{
if ( draw )
{
end = pb.PointToScreen( args.Location );
ControlPaint.DrawReversibleFrame
(
frame, Color.Black, FrameStyle.Dashed
);
frame = new Rectangle
(
start.X, start.Y, end.X - start.X, end.Y - start.Y
);
ControlPaint.DrawReversibleFrame
(
frame, Color.Black, FrameStyle.Dashed
);
}
};
}
}