如何为 TPageControl 的 Ttabsheet 实现关闭按钮
如何为 Firefox 等 TPageControl 的 Ttabsheet 实现关闭按钮?
编辑:
Delphi版本:Delphi 2010
操作系统:Windows XP 及更高版本
How can I implement a close button for a TTabsheet of a TPageControl like Firefox?
Edit:
Delphi Version: Delphi 2010
OS: Windows XP and up
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在有了主题支持(包括
Windows、UxTheme、主题
单元)!看起来像:
Now with Theme support (include
Windows, UxTheme, Themes
units)!Looks like:
正如其他答案所建议的那样,自己实现这一点通常是个好主意。不过,如果您已经在使用 Raize 组件,则支持此功能“开箱即用”。只需设置
TRzPageControl.ShowCloseButtonOnActiveTab := true
,并处理OnClose
事件。该组件负责各种选项卡布局/方向/形状/颜色的放置。[只是一个快乐的顾客]
It's often a good idea to implement this yourself, as the other answers have suggested. Just in case you are already using Raize Components, though, this feature is supported "out of the box". Just set
TRzPageControl.ShowCloseButtonOnActiveTab := true
, and handle theOnClose
event. The component takes care of placement for a variety of tab layouts/orientations/shapes/colors.[just a happy customer]
我过去所做的只是在 TPageControl 的右上角放置一个带有图形的 TBitBtn 。 TBitBtn 的父级的技巧与 TPageControl 相同,因此它实际上不在其中一个选项卡上。然后在单击该按钮时:
当释放当前 TTabControl 时,它会通知拥有它的 TPageControl。
What I have done in the past is just put a TBitBtn with a graphic in the upper right hand corner of the TPageControl. The trick i the parent of the TBitBtn is the same as the TPageControl, so it isn't actually on one of the tab sheets. Then in the click even for that button:
When the current TTabControl is freed it notifies the TPageControl that owns it.
我对这个例子做了一些改变:
- 创建类 TCloseTabSheet
- 该类具有属性 OnClose: TNotifyEvent,如果分配,将调用该属性
- 如果 TPageControl 的 TabSheet 不是该类,则没有关闭按钮
- 如果是则显示按钮。当您按下关闭按钮时,它会调用 OnClose
- 现在你不需要控制数组 FCloseButtonsRect,因为这个 Rect 存储在 TCloseTabSheet 中
I have changed a little this example:
- created class TCloseTabSheet
- this class has property OnClose: TNotifyEvent, which will be called if assigned
- if TabSheet of of TPageControl isn't that class then there is no close button
- if it is then Button showed. When you press close button it calls OnClose
- now you dont need to control the array FCloseButtonsRect, cause this Rects stored at TCloseTabSheet