2
A
回答
5
最簡單的方法是使用TPanel
。設置ParentBackground
到false
,BevelOuter
到bvNone
,Font.Color
到clWhite
,Font.Style
到[fsBold]
和Color
到你想要的背景顏色。然後在Caption
屬性中簡單地在文字前面放置一個或兩個空格,如' This is an ordinary TPanel.'
。
Screenshot http://privat.rejbrand.se/tpanelspaceprefix.png
更優雅soution是寫一個自定義的控制。這非常簡單。例如:
unit CaptionBar;
interface
uses
Windows, SysUtils, Classes, Controls, Graphics;
type
TCaptionBar = class(TCustomControl)
private
FColor: TColor;
FCaption: TCaption;
FEllipsis: boolean;
FIndent: integer;
procedure SetCaption(const Value: TCaption);
procedure SetColor(const Value: TColor);
procedure SetEllipsis(const Value: boolean);
procedure SetIndent(const Value: integer);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
property Font;
property Anchors;
property Align;
property Caption: TCaption read FCaption write SetCaption;
property Color: TColor read FColor write SetColor default clSkyBlue;
property Ellipsis: boolean read FEllipsis write SetEllipsis default true;
property Indent: integer read FIndent write SetIndent default 4;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Rejbrand 2009', [TCaptionBar]);
end;
{ TCaptionBar }
constructor TCaptionBar.Create(AOwner: TComponent);
begin
inherited;
FIndent := 4;
FColor := clSkyBlue;
FEllipsis := true;
end;
procedure TCaptionBar.Paint;
const
Ellipsis: array[boolean] of cardinal = (0, DT_END_ELLIPSIS);
var
r: TRect;
begin
inherited;
Canvas.Brush.Color := FColor;
Canvas.FillRect(ClientRect);
r := ClientRect;
r.Left := r.Left + FIndent;
Canvas.Font.Assign(Font);
DrawText(Canvas.Handle,
PChar(FCaption),
length(FCaption),
r,
DT_SINGLELINE or DT_LEFT or DT_VCENTER or Ellipsis[FEllipsis]);
end;
procedure TCaptionBar.SetCaption(const Value: TCaption);
begin
if not SameStr(FCaption, Value) then
begin
FCaption := Value;
Invalidate;
end;
end;
procedure TCaptionBar.SetColor(const Value: TColor);
begin
if FColor <> Value then
begin
FColor := Value;
Invalidate;
end;
end;
procedure TCaptionBar.SetEllipsis(const Value: boolean);
begin
if FEllipsis <> Value then
begin
FEllipsis := Value;
Invalidate;
end;
end;
procedure TCaptionBar.SetIndent(const Value: integer);
begin
if FIndent <> Value then
begin
FIndent := Value;
Invalidate;
end;
end;
end.
3
將一個標籤放入面板,縮進(設置Left屬性> 0)並正確設置面板顏色。
相關問題
- 1. Django模板:Wordwrap和縮進塊文本
- 2. Outlook 2007超鏈接和文本縮進
- 3. CSS:文本縮進和:之前
- 4. 使用「文本縮進」隱藏文本
- 5. 文本字段文本縮進
- 6. VB.NET:DataGridView ColumnHeader文本縮進值
- 7. UILabel文本偏移/縮進
- 8. HTML中的文本縮進
- 9. 縮進摺疊文本
- 10. CSS:文本縮進和文本對齊被忽略
- 11. 文本縮進-9999px ..根本不工作
- 12. vim關閉自動縮進自述文件和文本文件
- 13. 解析縮進文本文件
- 14. 將縮進文本寫入文件
- 15. 縮進正文文本但不是大塊引號和圖像
- 16. 縮進和Xcode
- 17. 文本壓縮JavaScript和PHP
- 18. 縮放文本和寬度
- 19. 文本陰影和縮放
- 20. ScintillaNET中的縮進和智能縮進
- 21. 基本縮進 - Python
- 22. 使用Javascript縮進選定文本
- 23. 文本縮進與Excel到Word宏
- 24. Rails ActionMailer查看文本縮進問題
- 25. 腳本來縮進actionscript 3文件?
- 26. 將文本縮進爲多級數組?
- 27. 如何回顯文本與縮進
- 28. Safari 8文本縮進問題
- 29. 基於Python文本的遊戲縮進
- 30. 對齊縮進到崇高的文本
我以爲我需要做一些TPanel的標題。 – maxfax
我可能會將標籤設置爲alCentre(或者它是否相同),並使用頂部,左側和右側錨點來獲取始終居中居中的標題,即使面板調整大小也是如此。 –
標題未在上圖中居中。 –