Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to mirror text horizontally or vertically on a TPaintBox Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
29-Aug-02
Category
Graphic
Language
Delphi 2.x
Views
100
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to mirror text horizontally or vertically on a TPaintBox

Answer:

This is actually not quite straightforward. The best way to do that is to first 
paint the text onto an off-screen bitmap and then paint that bitmap on screen using 
some weird coordinate manipulations. Drop a TPaintbox on the screen and connect a 
method to its OnPaint handler. Change the handler to the code below to see how this 
works:
1   
2   procedure TForm1.PaintBox1Paint(Sender: TObject);
3   const
4     test = 'Hello world';
5   var
6     bmp: TBitmap;
7     cv: TCanvas;
8     ext: TSize;
9     r: TRect;
10  begin
11    cv := (Sender as TPaintbox).canvas;
12    ext := cv.TextExtent(test);
13    bmp := TBitmap.Create;
14    try
15      bmp.Width := ext.cx;
16      bmp.Height := ext.cy;
17      bmp.Canvas.Brush := cv.Brush;
18      bmp.Canvas.Font := cv.Font;
19      bmp.Canvas.FillRect(bmp.canvas.cliprect);
20      bmp.Canvas.TextOut(0, 0, test);
21      {draw text in normal orientation}
22      cv.Draw(0, 0, bmp);
23      r := Rect(ext.cx, 0, 0, ext.cy);
24      OffsetRect(r, 0, ext.cy);
25      {draw text horizontally mirrored}
26      cv.CopyRect(r, bmp.canvas, bmp.canvas.ClipRect);
27      r := Rect(0, ext.cy, ext.cx, 0);
28      OffsetRect(r, 0, 2 * ext.cy);
29      {draw text vertically mirrored}
30      cv.CopyRect(r, bmp.canvas, bmp.canvas.ClipRect);
31    finally
32      bmp.Free
33    end;
34  end;


The key here is to set up the target rectangle for CopyRect with left and right or top and bottom switched. Be warned, there is a slight potential that this code will cause acute indigestion for some video drivers!

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC