Drawing a rubber band Rectangle | Dessiner un 'rubber band' rectangle |
A
rubber band is a
line or a rectangle that stretch when you move the mouse. If you don't
know what I mean, the selection rectangle of a graphic program, for
instance in Paint.exe, is a rubber band.
The code below uses the canvas property of a TImage object to draw a rubber band rectangle. You can, of course, modify the code to use another object canvas. |
Un
rubber band est une ligne ou un rectangle qui se redessine en fonction
des mouvement de la souris. Le rectangle de sélection dans
Paint.exe, par exemple, est un rubber band.
Le code, ci-dessous, utilise la propriété canvas d'un TImage pour dessiner un 'rubber band' rectangle mais vous pouvez, bien sur, modifié le programme pour l'adapter à un autre contrôle. |
Put these declarations in the header file (Unit.h): | Placez ces déclarations dans le fichier d'entête de votre projet (Unit.h) : |
bool Drawing; |
Now, place this code in your .cpp file. The code uses three events of the TImage (OnMouseMove, OnMouseDown and OnMouseUp) and one function (DrawRect). | Placez,
maintenant, le code suivant dans le fichier .cpp. Le programme utilise trois événements du TImage (OnMouseMove, OnMouseDown and OnMouseUp) et une fonction (DrawRect). |
//Add this line in the constructor |