我在應用程序中有一個TPanel,但有另一個外觀。
爲此,我需要一個彩色標題欄和圓角,就像在某些用戶界面中一樣,如it 您是否知道任何組件或庫? (首選開源,但不只)。
我試過TJVCaptionPanel沒關係,但需要四捨五入。德爾福7中的圓角標題「TPanel」
8
A
回答
20
是否這樣?
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
11
如果你想圓您想要的任何角落,試試這個:
procedure RoundCornerOf(Control: TWinControl) ;
var
R: TRect;
Rgn: HRGN;
begin
with Control do
begin
R := ClientRect;
rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 20, 20) ;
Perform(EM_GETRECT, 0, lParam(@r)) ;
InflateRect(r, - 4, - 4) ;
Perform(EM_SETRECTNP, 0, lParam(@r)) ;
SetWindowRgn(Handle, rgn, True) ;
Invalidate;
end;
end;
相關問題
- 1. 德爾福 - 從TPanel
- 2. 使德爾福TPanel字幕包裝
- 3. 德爾福圓角邊框按鈕
- 4. 圓角矩形在德爾福
- 5. 德爾福7德爾福XE2 res文件問題
- 6. 在德爾福7
- 7. 德爾福7 __ArrayList
- 8. 德爾福7內存問題
- 9. 德爾福7和事件
- 10. 德爾福7寡婦8.1
- 11. 德爾福7繼承
- 12. 德爾福7和Windows Vista
- 13. 德爾福7 TAdoQuery太慢
- 14. 德爾福7對象undefinedat
- 15. 轉換德爾福7代碼與德爾福2009年工作
- 16. 翻譯代碼DLL注入德爾福7德爾福XE2
- 17. 德爾福7中的Orbix客戶端
- 18. 德爾福7中的模態形式
- 19. 更改德爾福7中的字符
- 20. 德爾福XE8奇怪的標題
- 21. 德爾福 - 第二種形式的重複tpanel和tbuttons
- 22. 的ReportBuilder 7.x和德爾福7.X問題
- 23. 德爾福v.Word - 如何從德爾福
- 24. 德爾福HID Delphi7和德爾福XE2
- 25. 德爾福7的TImage和的TImageList
- 26. 查找財產TObject的德爾福7
- 27. 德爾福7 BDE的SQL Server 2012
- 28. 使用德爾福的7-Zip?
- 29. 德爾福7與CodeRush的滾輪
- 30. 德爾福7的Jabber/XMPP庫
優秀的,它的工作原理(有一些修改爲D7)......但什麼是執照 ? – philnext 2011-04-22 14:15:12
@philnext:我剛寫完了。你可以用你喜歡的任何方式使用它。 – 2011-04-22 14:16:16
好的,謝謝!但你爲什麼不把它放在'開源' – philnext 2011-04-22 14:22:30