| 12
 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
 
 | TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
   //fond blanc de Timage
    Image1->Canvas->Brush->Color=clWhite;
    Image1->Canvas->FillRect(Image1->Canvas->ClipRect);
}
//---------------------------------------------------------------------------
//fonction de dessin de rectangle
void __fastcall DessinerRectangle(TCanvas * Canvas,int top, int left,int height,int width,TColor col_interior,TColor col_border)
{
   if(Canvas==NULL) return;
   TColor SaveBrushColor =Canvas->Brush->Color;
   TColor SavePenColor = Canvas->Pen->Color;
   Canvas->Brush->Color= col_interior;
   Canvas->Pen->Color =  col_border;
   Canvas->Rectangle(left,top,left+width,top+height);
   Canvas->Brush->Color=SaveBrushColor;
   Canvas->Pen->Color = SavePenColor;
}
 
//fonction desin de rectangle temporaire
void __fastcall DessinerRectangleVide(TCanvas * Canvas,int top, int left,int height,int width,TColor col_border)
{
   if(Canvas==NULL) return;
 
   TColor SavePenColor = Canvas->Pen->Color;
   TBrushStyle SaveStyle = Canvas->Brush->Style;
   Canvas->Brush->Style = bsClear;
   Canvas->Pen->Color =  col_border;
   Canvas->Rectangle(left,top,left+width,top+height);
   Canvas->Pen->Color = SavePenColor;
   Canvas->Brush->Style =SaveStyle;
}
 
 
 
//evenement OnMouseDown de TPaintbox
void __fastcall TForm1::PaintBox1MouseDown(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        appuye=true;        // le click est maintenu
}
//---------------------------------------------------------------------------
 
//evenement OnMouseUp de TPaintbox
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
      TMouseButton Button, TShiftState Shift, int X, int Y)
{
        appuye=false; // le click est relaché
        if(SpeedBtnRect->Down){  
          // alors on dessine sur l'Image
          DessinerRectangle(Image1->Canvas,Y,X,50,50,clRed,clYellow);
        }
}
//---------------------------------------------------------------------------
//evenement OnMouseMove de TPaintbox
void __fastcall TForm1::PaintBox1MouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
   if(appuye){  // si le click est maintenu on efface le dernier rectangle temporaire
        PaintBox1->Repaint();
   }
   if(SpeedBtnRect->Down && appuye){       //si click maintenu et bouton rectangle enfoncé
 
       //on dessine le rectangle temporaire
       DessinerRectangleVide(PaintBox2->Canvas,Y,X,50,50,clBlack);
 
   }
}
//--------------------------------------------------------------------------- |