圆形并标题为“TPanel”在德尔福7 [英] Rounded and titled "TPanel" in Delphi 7

查看:331
本文介绍了圆形并标题为“TPanel”在德尔福7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在我的应用程序中有一个TPanel,但是另一个看起来。

为了我,我想要一个彩色的标题栏,并且像在一些用户界面(如it
您是否知道任何组件或库? (优先开源,但不仅仅是)。

我试过TJVCaptionPanel它可以,但需要向上角。

解决方案

p>像这样?

  unit CustomCaptionPanel; 

接口

使用
Windows,SysUtils,类,控件,图形;

type
TCustomCaptionPanel = class(TCustomControl)
private const
DEFAULT_BORDER_COLOR = $ 0033CCFF;
DEFAULT_CLIENT_COLOR = clWindow;
DEFAULT_BORDER_RADIUS = 16;
private
{私有声明}
FBorderColor:TColor;
FClientColor:TColor;
FBorderRadius:integer;
FCaption:TCaption;
FAlignment:TAlignment;
程序SetBorderColor(BorderColor:TColor);
程序SetClientColor(ClientColor:TColor);
程序SetBorderRadius(BorderRadius:integer);
程序SetCaption(const Caption:TCaption);
程序SetAlignment(Alignment:TAlignment);
protected
procedure Paint;覆盖
{受保护的声明}
public
构造函数Create(AOwner:TComponent);覆盖
{公开声明}
发布
{发布声明}
属性颜色;
属性Caption read FCaption write SetCaption;
属性对齐:TAlignment读取FAlignment写入SetAlignment默认taCenter;
属性Font;
属性BorderColor:TColor读取FBorderColor写入SetBorderColor默认值DEFAULT_BORDER_COLOR;
属性ClientColor:TColor读取FClientColor写入SetClientColor默认值DEFAULT_CLIENT_COLOR;
属性BorderRadius:整数读FBorderRadius写SetBorderRadius默认DEFAULT_BORDER_RADIUS;
结束

程序注册;

执行

程序注册;
begin
RegisterComponents('Rejbrand 2009',[TCustomCaptionPanel]);
结束

{TCustomCaptionPanel}

构造函数TCustomCaptionPanel.Create(AOwner:TComponent);
开始
继承;
ControlStyle:= [csAcceptsControls,csCaptureMouse,csClickEvents,
csSetCaption,csOpaque,csDoubleClicks,csReplicatable,csPannable];
FBorderColor:= DEFAULT_BORDER_COLOR;
FClientColor:= DEFAULT_CLIENT_COLOR;
FBorderRadius:= DEFAULT_BORDER_RADIUS;
FAlignment:= taCenter;
结束

程序TCustomCaptionPanel.Paint;
var
r:TRect;
const
对齐:整数的数组[TAlignment] =(DT_LEFT,DT_RIGHT,DT_CENTER);
开始
继承;
Canvas.Pen.Color:= FBorderColor;
Canvas.Brush.Color:= FBorderColor;
Canvas.Brush.Style:= bsSolid;
Canvas.FillRect(Rect(FBorderRadius,
0,
ClientWidth - FBorderRadius,
FBorderRadius));
Canvas.Ellipse(Rect(0,
0,
2 * FBorderRadius,
2 * FBorderRadius));
Canvas.Ellipse(Rect(ClientWidth - 2 * FBorderRadius,
0,
ClientWidth,
2 * FBorderRadius));
Canvas.Brush.Color:= FClientColor;
Canvas.Rectangle(Rect(0,
FBorderRadius,
ClientWidth,
ClientHeight));
Canvas.Font.Assign(Self.Font);
r:= Rect(FBorderRadius,0,ClientWidth - FBorderRadius,FBorderRadius);
Canvas.Brush.Style:= bsClear;
DrawText(Canvas.Handle,
PChar(Caption),
length(Caption),
r,
DT_SINGLELINE或DT_LEFT或DT_VCENTER或DT_END_ELLIPSIS或对齐[FAlignment]) ;
结束

程序TCustomCaptionPanel.SetAlignment(Alignment:TAlignment);
begin
如果FAlignment<>对齐然后
开始
FAlignment:=对齐;
无效;
结束
结束

程序TCustomCaptionPanel.SetBorderColor(BorderColor:TColor);
begin
如果FBorderColor<> BorderColor然后
begin
FBorderColor:= BorderColor;
无效;
结束
结束

程序TCustomCaptionPanel.SetBorderRadius(BorderRadius:integer);
begin
如果FBorderRadius<>然后边框边缘
begin
FBorderRadius:= BorderRadius;
无效;
结束
结束

程序TCustomCaptionPanel.SetCaption(const Caption:TCaption);
begin
如果不是SameStr(FCaption,Caption)然后
begin
FCaption:= Caption;
无效;
结束
结束

程序TCustomCaptionPanel.SetClientColor(ClientColor:TColor);
begin
如果FClientColor<> ClientColor然后
begin
FClientColor:= ClientColor;
无效;
结束
结束

结束。

屏幕截图的自定义字幕面板控件http://privat.rejbrand.se/customcaptionpanel.png


I would have a TPanel in my application but with another look.
For it I want a colored title bar and the up corner rounded just like in some user interfaces like it Do you know any component or library for it ? (Prefered Open source but not only).
I tried TJVCaptionPanel it's OK but needs rounded up corner.

解决方案

Like this?

unit CustomCaptionPanel;

interface

uses
  Windows, SysUtils, Classes, Controls, Graphics;

type
  TCustomCaptionPanel = class(TCustomControl)
  private const
    DEFAULT_BORDER_COLOR = $0033CCFF;
    DEFAULT_CLIENT_COLOR = clWindow;
    DEFAULT_BORDER_RADIUS = 16;
  private
    { Private declarations }
    FBorderColor: TColor;
    FClientColor: TColor;
    FBorderRadius: integer;
    FCaption: TCaption;
    FAlignment: TAlignment;
    procedure SetBorderColor(BorderColor: TColor);
    procedure SetClientColor(ClientColor: TColor);
    procedure SetBorderRadius(BorderRadius: integer);
    procedure SetCaption(const Caption: TCaption);
    procedure SetAlignment(Alignment: TAlignment);
  protected
    procedure Paint; override;
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    { Public declarations }
  published
    { Published declarations }
    property Color;
    property Caption read FCaption write SetCaption;
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property Font;
    property BorderColor: TColor read FBorderColor write SetBorderColor default DEFAULT_BORDER_COLOR;
    property ClientColor: TColor read FClientColor write SetClientColor default DEFAULT_CLIENT_COLOR;
    property BorderRadius: integer read FBorderRadius write SetBorderRadius default DEFAULT_BORDER_RADIUS;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Rejbrand 2009', [TCustomCaptionPanel]);
end;

{ TCustomCaptionPanel }

constructor TCustomCaptionPanel.Create(AOwner: TComponent);
begin
  inherited;
  ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
    csSetCaption, csOpaque, csDoubleClicks, csReplicatable, csPannable];
  FBorderColor := DEFAULT_BORDER_COLOR;
  FClientColor := DEFAULT_CLIENT_COLOR;
  FBorderRadius := DEFAULT_BORDER_RADIUS;
  FAlignment := taCenter;
end;

procedure TCustomCaptionPanel.Paint;
var
  r: TRect;
const
  Alignments: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
  inherited;
  Canvas.Pen.Color := FBorderColor;
  Canvas.Brush.Color := FBorderColor;
  Canvas.Brush.Style := bsSolid;
  Canvas.FillRect(Rect(FBorderRadius,
    0,
    ClientWidth - FBorderRadius,
    FBorderRadius));
  Canvas.Ellipse(Rect(0,
    0,
    2*FBorderRadius,
    2*FBorderRadius));
  Canvas.Ellipse(Rect(ClientWidth - 2*FBorderRadius,
    0,
    ClientWidth,
    2*FBorderRadius));
  Canvas.Brush.Color := FClientColor;
  Canvas.Rectangle(Rect(0,
    FBorderRadius,
    ClientWidth,
    ClientHeight));
  Canvas.Font.Assign(Self.Font);
  r := Rect(FBorderRadius, 0, ClientWidth - FBorderRadius, FBorderRadius);
  Canvas.Brush.Style := bsClear;
  DrawText(Canvas.Handle,
    PChar(Caption),
    length(Caption),
    r,
    DT_SINGLELINE or DT_LEFT or DT_VCENTER or DT_END_ELLIPSIS or Alignments[FAlignment]);
end;

procedure TCustomCaptionPanel.SetAlignment(Alignment: TAlignment);
begin
  if FAlignment <> Alignment then
  begin
    FAlignment := Alignment;
    Invalidate;
  end;
end;

procedure TCustomCaptionPanel.SetBorderColor(BorderColor: TColor);
begin
  if FBorderColor <> BorderColor then
  begin
    FBorderColor := BorderColor;
    Invalidate;
  end;
end;

procedure TCustomCaptionPanel.SetBorderRadius(BorderRadius: integer);
begin
  if FBorderRadius <> BorderRadius then
  begin
    FBorderRadius := BorderRadius;
    Invalidate;
  end;
end;

procedure TCustomCaptionPanel.SetCaption(const Caption: TCaption);
begin
  if not SameStr(FCaption, Caption) then
  begin
    FCaption := Caption;
    Invalidate;
  end;
end;

procedure TCustomCaptionPanel.SetClientColor(ClientColor: TColor);
begin
  if FClientColor <> ClientColor then
  begin
    FClientColor := ClientColor;
    Invalidate;
  end;
end;

end.

Screenshot of the custom-caption panel control http://privat.rejbrand.se/customcaptionpanel.png

这篇关于圆形并标题为“TPanel”在德尔福7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆