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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
private bool _selecting = false;
private Point _selectionStartPoint = Point.Empty;
private Point _selectionEndPoint = Point.Empty;
private Rectangle _selectionRect = Rectangle.Empty;
// private Point _LastPoint = Point.Empty;
public Rectangle _LastselectionRect = Rectangle.Empty;
private Point _laststrart = Point.Empty;
private Point _lastend = Point.Empty;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
this.Invalidate();
this._selecting = true;
//pour lecran
this._selectionStartPoint = this.PointToScreen(new Point(e.X, e.Y));
this._selectionEndPoint = Point.Empty;
this._selectionRect = Rectangle.Empty;
//pour le last ;)
_laststrart = new Point(e.X, e.Y);//les vrai valeures ;)
_lastend = Point.Empty;
_LastselectionRect = Rectangle.Empty;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if (this._selecting)//pour dessiner le rect
{
//effacer le last
// ControlPaint.DrawFocusRectangle(this.CreateGraphics(), _LastselectionRect, Color.Red, Color.Transparent);
// 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
);
// calcul du nouveau rectangle vrai ;)
_lastend =new Point(e.X, e.Y);
_LastselectionRect = new Rectangle(
_laststrart.X,
_laststrart.Y,
_lastend.X - _laststrart.X,
_lastend.Y - _laststrart.Y
);
////pour le rectangle de selection
//Graphics g = this.CreateGraphics();//.Graphics;
//Rectangle inner = _selectionRect;
//inner.Inflate(-2, -2);
//ControlPaint.DrawSelectionFrame(g, false, _selectionRect, inner, Color.Transparent);
// dessin du nouveau rectangle
//ControlPaint.DrawReversibleFrame(this._selectionRect, this.BackColor, SELECTION_STYLE);
//pour le focus
// ControlPaint.DrawFocusRectangle(this.CreateGraphics(), _LastselectionRect, Color.Red, Color.Transparent);
}
}
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);
//ControlPaint.DrawReversibleFrame(this._selectionRect, this.BackColor, SELECTION_STYLE);
// ControlPaint.DrawFocusRectangle(this.CreateGraphics(),_LastselectionRect, Color.Red, this.BackColor);
_LastselectionRect = _selectionRect;
}
this._selecting = false;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle inner = _selectionRect;
inner.Inflate(-2, -2);
ControlPaint.DrawSelectionFrame(g, true, _selectionRect, inner, Color.Black);
} |
Partager