Solved

PANEL

Posted on 1998-07-22
4
178 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
Comment Utility
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
Comment Utility
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
Comment Utility
Nevertheless, you can write everything you want in the Paint procedure.
sassas
0
 
LVL 4

Accepted Solution

by:
d003303 earned 20 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now