Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PANEL

Posted on 1998-07-22
4
Medium Priority
?
187 Views
Last Modified: 2010-05-18
How to change the color of the edge of TPanel in Delphi?
In Standard TPanel, the edge is always white
0
Comment
Question by:daniel_c
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:sassas081597
ID: 1358419
How about writing your own component from TCustomPanel, add the property FEdgeColor:TColor and override the Paint procedure?
If you wish,I think, everyone can write this component for you.
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1358420
As far as I know, Delphi uses clBtnHighlight and clBtnShadow to draw the edges of the panel.  These are standard Windows colors for button edges.

JB
0
 
LVL 1

Expert Comment

by:sassas081597
ID: 1358421
Nevertheless, you can write everything you want in the Paint procedure.
sassas
0
 
LVL 4

Accepted Solution

by:
d003303 earned 80 total points
ID: 1358422
Right, Delphi sticks to the system-wide colors when drawing panels. You could derive from TCustomPanel (or TPanel) and overwrite the paint procedure as sassas said.
Paste the VCL source code in and select your own colors.

All right, much said, here it's done:

unit ColoredPanel;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TColoredPanel = class(TPanel)
  private
    { Private declarations }
    FTopColor,
    FBottomColor : TColor;
    procedure SetTopColor(NewValue : TColor);
    procedure SetBottomColor(NewValue : TColor);
  protected
    { Protected declarations }
    procedure Paint; override;
  public
    { Public declarations }
  published
    { Published declarations }
    constructor Create(AOwner : TComponent); override;
    property TopColor: TColor read FTopColor write SetTopColor;
    property BottomColor: TColor read FBottomColor write SetBottomColor;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Slash', [TColoredPanel]);
end;

procedure TColoredPanel.SetTopColor(NewValue : TColor);
begin
  if NewValue <> FTopColor then
   begin
     FTopColor := NewValue;
     Invalidate;
   end;
end;

procedure TColoredPanel.SetBottomColor(NewValue : TColor);
begin
  if NewValue <> FBottomColor then
   begin
     FBottomColor := NewValue;
     Invalidate;
   end;
end;

constructor TColoredPanel.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FTopColor := clBtnHighlight;
  FBottomColor := clBtnShadow;
end;

procedure TColoredPanel.Paint;
var
  Rect: TRect;
  TopColor, BottomColor: TColor;
  FontHeight: Integer;
const
  Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);

  procedure AdjustColors(Bevel: TPanelBevel);
  begin
    TopColor := FTopColor;
    if Bevel = bvLowered then TopColor := FBottomColor;
    BottomColor := FBottomColor;
    if Bevel = bvLowered then BottomColor := FTopColor;
  end;

begin
  Rect := GetClientRect;
  if BevelOuter <> bvNone then
  begin
    AdjustColors(BevelOuter);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  Frame3D(Canvas, Rect, Color, Color, BorderWidth);
  if BevelInner <> bvNone then
  begin
    AdjustColors(BevelInner);
    Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  end;
  with Canvas do
  begin
    Brush.Color := Color;
    FillRect(Rect);
    Brush.Style := bsClear;
    Font := Self.Font;
    FontHeight := TextHeight('W');
    with Rect do
    begin
      Top := ((Bottom + Top) - FontHeight) div 2;
      Bottom := Top + FontHeight;
    end;
    DrawText(Handle, PChar(Caption), -1, Rect, (DT_EXPANDTABS or
      DT_VCENTER) or Alignments[Alignment]);
  end;
end;

end.

Slash/d003303
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question