Solved

PANEL

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month4 days, 23 hours left to enroll

636 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