private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { bMouseDown = true; picBoard.Capture = true;
OldPos = new Point(e.X, e.Y); // point de départ du nouveau tracé }
private void picBoard_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
bMouseDown = false;
picBoard.Capture = false;
}
private void picBoard_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) {
if (bMouseDown){
Graphics g = Graphics.FromImage(bmpInterne);
g.SmoothingMode = SmoothingMode.AntiAlias; // mode antialiasing
Pen pen = new Pen(PenColor,3); // couleur courante, épaisseur 3
if (OldPos!=new Point(-1,-1))
g.DrawLine(pen,OldPos,new Point(e.X,e.Y)); // tracé de la ligne
// Calcul de la zone à redessiner ( recherche du rectangle circonscrit) int offsetx = Math.Min(e.X,OldPos.X); int offsety = Math.Min(e.Y,OldPos.Y); Rectangle rInvalid = new Rectangle(offsetx,offsety, Math.Abs(OldPos.X-e.X),Math.Abs(OldPos.Y-e.Y)); rInvalid.Inflate(3,3); // A cause de l'épaisseur du stylo picBoard.Invalidate(rInvalid,true); OldPos = new Point( e.X, e.Y ); };
}
private void button1_Click(object sender, System.EventArgs e) {
DlgColor.Color = PenColor;
if (DlgColor.ShowDialog() == DialogResult.OK)
PenColor = DlgColor.Color; // nouvelle couleur de dessin
}
|