Réponse acceptée !
Salut,
Bon, j'arrive après la bataille mais mieux vaut tard que jamais ^^
L'inconvénient avec la méthode citée plus haut est quand même que le trait de sélection n'est pas dessiné sur les contrôles enfants.
Pour celà notre ami le Framework contient la classe ControlPaint et sa méthode DrawReversibleFrame :-)
private bool _selecting = false;
private Point _selectionStartPoint = Point.Empty;
private Point _selectionEndPoint = Point.Empty;
private Rectangle _selectionRect = Rectangle.Empty;
private const FrameStyle SELECTION_STYLE = FrameStyle.Dashed;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown (e);
if ( e.Button == MouseButtons.Left )
{
this._selecting = true;
this._selectionStartPoint = this.PointToScreen(new Point(e.X, e.Y));
this._selectionEndPoint = Point.Empty;
this._selectionRect = Rectangle.Empty;
}
}
protected override void OnMouseMove( MouseEventArgs e )
{
base.OnMouseMove( e );
if ( this._selecting )
{
// efface le rectangle de sléection précédent
ControlPaint.DrawReversibleFrame(this._selectionRect, this.BackColor, SELECTION_STYLE);
// calcul du nouveau rectangle
this._selectionEndPoint = this.PointToScreen(new Point(e.X, e.Y));
this._selectionRect = new Rectangle(
this._selectionStartPoint.X,
this._selectionStartPoint.Y,
this._selectionEndPoint.X - this._selectionStartPoint.X,
this._selectionEndPoint.Y - this._selectionStartPoint.Y
);
// dessin du nouveau rectangle
ControlPaint.DrawReversibleFrame(this._selectionRect, this.BackColor, SELECTION_STYLE);
}
}
protected override void OnMouseUp( MouseEventArgs e )
{
base.OnMouseUp( e );
if ( this._selecting )
{
// efface le rectangle de sélection
ControlPaint.DrawReversibleFrame(this._selectionRect, this.BackColor, SELECTION_STYLE);
}
this._selecting = false;
}
/*
coq
MVP Visual C#
*/