简体   繁体   English

在Delphi中实现'标签面板'控件?

[英]Implementing a 'tag panel' control in Delphi?

Please have a look at this screenshot 请看一下这个截图

alt text http://www.maclife.com/files/u18/Yep3-big.jpg 替代文字http://www.maclife.com/files/u18/Yep3-big.jpg

I think these are the main features of such a 'tag panel': 我认为这些是'标签面板'的主要特征:

1) Each tag on the panel is a standalone control and can be clicked 1)面板上的每个标签都是独立控件,可以单击

2) Auto line wrapping when there is not enough space to show the next tag in the current line. 2)当没有足够的空间显示当前行中的下一个标记时自动换行。

3) Rounded corner rectangle border for each tag is a nice-to-have feature. 3)每个标签的圆角矩形边框是一个很好的功能。

I want to implement the similar function in Delphi, Is there an existing control to do this? 我想在Delphi中实现类似的功能,是否有现成的控件来执行此操作? If not, what's the best way to implement such a control? 如果没有,实施这种控制的最佳方法是什么?

Thank you. 谢谢。

When you are on a recent Delphi version use a TFlowPanel and some appropriate controls for the tags. 当您使用最近的Delphi版本时,请使用TFlowPanel和一些适当的标记控件。 A simple TButton or a TLinkLabel should do for that. 一个简单的TButton或TLinkLabel就可以做到这一点。

Each clickable tag doesn't necessarily have to be its own control. 每个可点击标签不一定必须是它自己的控件。 It just has to be a region that you can detect being clicked. 它只需要是一个可以检测到被点击的区域。

Suppose you represent each area as a Windows region . 假设您将每个区域表示为Windows区域 You can figure out how wide each one should be based on its text with the TCanvas.TextExtent function. 您可以根据TCanvas.TextExtent函数的文本确定每个文本的宽度。 Then create a region with a function like CreateRectRgn . 然后使用CreateRectRgn函数创建一个区域。 For rounded corners, try CreateRoundRectRgn instead. 对于圆角,请尝试使用CreateRoundRectRgn You can test for mouse events in each region with the PtInRegion function. 您可以使用PtInRegion函数测试每个区域中的鼠标事件。 You can paint borders around them with FrameRgn . 您可以使用FrameRgn在它们周围绘制边框。 The last obstacle is to draw them on the screen so they'll all fit. 最后一个障碍是在屏幕上绘制它们以便它们都适合。 You're creating the regions and you know their widths, so assign tags to a row until you run out of space, and then start the next line. 您正在创建区域并且知道它们的宽度,因此将标记分配给行直到用完空间,然后开始下一行。

There are two possible solutions to custom alignment in Delphi 7. You can make your own flowpanel by deriving from TCustomPanel and override the AlignControls( )-method, or you can set alignment to alCustom and handle the OnAlignPosition-event. 在Delphi 7中有两种可能的自定义对齐解决方案。您可以通过从TCustomPanel派生并覆盖AlignControls()方法来创建自己的流程板,也可以将对齐设置为alCustom并处理OnAlignPosition事件。

I guess I would have gone for the TCustomPanel-derivative option. 我想我会选择TCustomPanel衍生版本。 TFlowPanel in form Delphi 2007 uses that option- I have to admit, though, that I have never tried either my self... Delphi 2007形式的TFlowPanel使用了这个选项 - 但我必须承认,我从来没有尝试过我的自我......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM