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 create a TRichEdit with a tiled background 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
12-Oct-02
Category
Reporting /Printing
Language
Delphi 2.x
Views
92
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

Does anyone know how to use a tiled picture as the background for a TRichEdit 
control?

Answer:

For a standard TRichEdit there seems to be no way to make it transparent or paint 
its background with a tiled bitmap. But there is a workaround if you're using the 
Win2000 operating system. There you can make your control transparent by setting 
the WS_EX_LAYERED constant to the window extended style and then calling the 
SetLayeredWindowAttributes Win API function.

The example listed below is a TRichEdit control with a DrawStyle property. 
Depending on its value, the control will have a transparent background or will draw 
itself with an alpha transparency.

1   { ... }
2   type
3     TDrawStyle = (ds_Transparent, ds_NotDistinctly, dsNormal);
4   
5     MyTransparentRichEdit = class(TRichEdit)
6     protected
7       FDrawStyle: TDrawStyle;
8       procedure CreateParams(var Params: TCreateParams); override;
9       procedure CreateWnd; override;
10      procedure SetDrawStyle(AValue: TDrawStyle);
11    public
12      constructor Create(AOwner: TComponent); override;
13    published
14      property DrawStyle: TDrawStyle read FDrawStyle write SetDrawStyle;
15    end;
16  
17    { ... }
18  
19  constructor MyTransparentRichEdit.Create(AOwner: TComponent);
20  begin
21    inherited Create(AOwner);
22    FDrawStyle := dsNormal;
23  end;
24  
25  procedure MyTransparentRichEdit.CreateParams(var Params: TCreateParams);
26  begin
27    inherited CreateParams(Params);
28    if not (csDesigning in ComponentState) then
29    begin
30      Params.Style := Params.Style or WS_POPUP;
31      Params.ExStyle := Params.ExStyle + WS_EX_LAYERED;
32    end;
33  end;
34  
35  procedure MyTransparentRichEdit.CreateWnd;
36  var
37    XPoint: TPoint;
38  begin
39    if not (csDesigning in ComponentState) then
40    begin
41      XPoint := TWinControl(Owner).ClientToScreen(POINT(Left, Top));
42      Left := XPoint.X;
43      Top := XPoint.Y;
44    end;
45    inherited CreateWnd;
46    case FDrawStyle of
47      ds_Transparent:
48        SetLayeredWindowAttributes(Handle, ColorToRGB(Color), 255, LWA_COLORKEY);
49      ds_NotDistinctly:
50        SetLayeredWindowAttributes(Handle, 0, 150, LWA_ALPHA);
51    end;
52  end;
53  
54  procedure MyTransparentRichEdit.SetDrawStyle(AValue: TDrawStyle);
55  begin
56    if FDrawStyle <> AValue then
57    begin
58      FDrawStyle := AValue;
59      RecreateWnd;
60    end;
61  end;


			
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