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 change the border color of a TPanel 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
08-Dec-02
Category
VCL-General
Language
Delphi 2.x
Views
172
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Can I change black line color of the TPanel border (BorderStyle = bsSingle) into 
i.e. blue line color? I tried to trap the WM_NCPAINT message and to draw over the 
border line, but it's not working. The border line color is still black.

Answer:

That color is the COLOR_WINDOWFRAME, so you probably do not want to change it in 
general. But the NC paint handler should work. Here's some sample code to draw a 
border in red:

1   { ... }
2   type
3     TMyPanel = class(TPanel)
4     protected
5       procedure WM_NCPaint(var Msg: TWMNCPaint); message WM_NCPaint;
6     end;
7   
8   procedure TMyPanel.WM_NCPaint(var Msg: TWMNCPaint);
9   var
10    DC: HDC;
11    OldBrush: HBRUSH;
12    OldPen: HPEN;
13  begin
14    DC := 0;
15    OldBrush := 0;
16    OldPen := 0;
17    try
18      {Must use a WindowDC or you can't draw outside the client area}
19      DC := GetWindowDC(Handle);
20      {Use a "clear" brush and an appropriately colored pen}
21      OldBrush := SelectObject(DC, GetStockObject(NULL_BRUSH));
22      Canvas.Pen.Color := clRed;
23      OldPen := SelectObject(DC, Canvas.Pen.Handle);
24      {Draw the border}
25      Rectangle(DC, 0, 0, Width, Height);
26      {Tell Windows you did it}
27      Msg.Result := 0;
28    finally
29      {Clean up the mess you made}
30      if DC <> 0 then
31      begin
32        if OldPen <> 0 then
33          SelectObject(DC, OldPen);
34        if OldBrush <> 0 then
35          SelectObject(DC, OldBrush);
36        ReleaseDC(Handle, DC);
37      end;
38    end;
39  end;
40  
41  {Dynamic panel creation}
42  
43  { ... }
44  Panel := TMyPanel.Create(Self);
45  with Panel do
46  begin
47    Parent := Self;
48    Left := 10;
49    Top := 10;
50    {Don't try to do 3D borders or add beveling - keep it simple}
51    BevelOuter := bvNone;
52    BorderStyle := bsSingle;
53    Ctl3d := False;
54  end;
55  { ... }


			
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