| RTL referenceGlossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| GDI Graphics In Delphi | ||||||||||||||||||||||||||||||||||||||||
| Page 3: Drawing: Shapes | ||||||||||||||||||||||||||||||||||||||||
There are many shape drawing functions in TCanvas, and all are easy to use. Here are some useful ones:
The above list should help you create some reasonable drawing. There is one more useful function: TextOut. This allows you to draw text to the screen using the current Canvas font.
This is a very useful function. You can draw transparent text too, without the background filling. Nip along to the tips page (drawing transparent text). If you want to change the font used in TextOut, set details for the Canvas's Font property (of type TFont) - for example "Canvas.Font.Name := 'Verdana';", "Canvas.Font.Size := 24;" or "Canvas.Font.Color := clRed;".
I'd better quickly point out the Bounds function. This gives a TRect record, which just stores left, right, top and bottom integers. TRects are very useful (in the Windows API they are called RECTs, by the way). Bounds lets you specify a left and top position, and a width and height, and you will get a TRect with (left, top, left + width, top + height) in return. There is another function, Rect(), which does much the same thing but accepts the left, right, top and bottom coordinates directly. Finally, you could use SetRect from the Windows API if you wanted.
Here's some example code that randomly draws shapes:
![]() You might have noticed some shapes have a different outline color from their insides? This is what I mentioned above. The brush is used to fill the shape and the pen is used to outline it. Since the brush color is set randomly but the pen color is not, the difference between the two should be obvious. That's enough about this - you should be able to draw some simple shapes and text now. However, the issue of the disappearing graphics needs to be resolved. Question, Suggestions... Next page > Drawing vs. Painting > Page 1, 2, 3, 4, 5, 6, 7, 8, 9 |
||||||||||||||||||||||||||||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC. |
|
· NEXT ARTICLE:
Articles. More Delphi articles |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |


