Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PANEL

Posted on 1998-07-22
4
Medium Priority
?
188 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

972 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