Solved

PANEL

Posted on 1998-07-22
4
184 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 20 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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