[英]Add icons to TTabControl in Firemonkey
First of all I have to say that I've read this question of SO. 首先,我不得不说我已经阅读了SO的这个问题。 But actually it wasn't helpful for me. 但是实际上这对我没有帮助。
I want to add icons to TTabControl
but it doesn't seems as easy as I can do it in VCL ( TPageControl
). 我想向TTabControl
添加图标,但它似乎不像我在VCL( TPageControl
)中那样容易。 As you know there is no something like Image Index
in TTabControl
. 如您所知, TTabControl
没有像Image Index
的TTabControl
。
So what's the easiest way to do this? 那么最简单的方法是什么?
Thanks for your help. 谢谢你的帮助。
I would suggest not going down the route of modifying the style given the inherent 'copy and paste "inheritance"' nature of the exercise, which becomes an issue if you're targeting more than one OS (even just Windows 7 and Windows 8.x). 考虑到该练习固有的“复制和粘贴“继承””性质,我建议不要沿用修改样式的路线,如果您要针对多个操作系统(甚至是Windows 7和Windows 8),这将成为一个问题。 X)。 Instead, try this: 相反,请尝试以下操作:
1) For each item you want an icon on, change its TextAlign
property to taTrailing
and pad its Text
with four leading space characters. 1)对于要打开图标的每个项目,将其TextAlign
属性更改为taTrailing
并用四个前导空格字符填充其Text
。
2) Add one TImage
to the form per tab, and load small bitmaps into them as desired. 2)在每个标签的表单中添加一个TImage
,然后根据需要将小的位图加载到其中。
3) Associate each tab item with its image by (for example) assigning its TagObject
property to the image control in an OnCreate
handler for the form: 3)通过(例如)将其TagObject
属性分配给TagObject
的OnCreate
处理程序中的图像控件,从而将每个选项卡项与其图像相关联:
procedure TForm1.FormCreate(Sender: TObject);
begin
TabItem1.TagObject := Image1;
//...
end;
4) Assign each tab item's OnPaint
event the following shared event handler: 4)为每个选项卡项目的OnPaint
事件分配以下共享事件处理程序:
procedure TForm1.TabItemPaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
var
B: TBitmap;
SrcR, DstR: TRectF;
TabItem: TTabItem;
begin
TabItem := (Sender as TTabItem);
B := (TabItem.TagObject as TImage).Bitmap;
SrcR := RectF(0, 0, B.Width, B.Height);
DstR := SrcR;
DstR.Fit(RectF(ARect.Left, ARect.Top, ARect.Left + ARect.Height, ARect.Bottom));
if not TabItem.IsSelected then DstR.Offset(0, 1);
Canvas.DrawBitmap(B, SrcR, DstR, 1);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.