TabPage标题自定义 [英] TabPage header customization

查看:73
本文介绍了TabPage标题自定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我想在TabPage的标题中添加一个radiobutton。我查看了 FireFox-like Tab Control [ ^ ],但是如何添加真实控件,而不是图像它?

Hi!

I want to add a radiobutton to TabPage's header. I looked at FireFox-like Tab Control[^], but how can I add a real control, not an image of it?

推荐答案

因为根据定义,TabControl是一次一个查看器,从逻辑上讲,它只能使一个一组无线电按钮中的无线电按钮有效/选择的单选按钮:你为什么要这样做?



你引用的类似FireFox的TabControl什么出现是一个CheckBox来触发一个下拉菜单。



TabControl本身在添加方面被锁定控件:您只能将TabPages添加到TabControl本身,并且只将控件添加到单个TabPage。据我所知,你不能通过使用继承来创建自定义Tabs的自定义TabControl,除非你自己完成所有的绘图/绘画(OwnerDrawn)......这是一项重要的工作。



CP上有几篇文章将向您展示如何使用自定义选项卡创建OwnerDrawn TabControl,例如:绘制自己的选项卡 - 第二版[ ^ ]。



但是,如果你有动力和时间,还有另一种选择:从头开发自己的自定义TabControl。以下是我将如何继续:



1.创建一个UserControl,作为所有自定义TabPages的主容器。



2.创建一个UserControl,作为每个矩形TabPage的模板。



3.使用自定义创建UserControl区域(通过使用GraphicsPath定义并设置UserControl的区域)具有所需的Tab形状,并将用作所有选项卡的模板。如果您希望获得花哨并为第一个选项卡或最后一个选项卡设置不同形状的选项卡,则定义其他UserControl模板。在自定义选项卡上:放置你想要的任何控件(CheckBox,RadioButton,ComboBox)。



4.实现必要的'添加方法(在WinForms中模拟TabControl)将在步骤#2~3中开发的UserControls的新实例添加到主容器UserControl#1中,并调整自定义Tab UserControl#3相对于TabPage UserControl模板#2的x轴位置,以便您实现标准TabControl的外观。



然后,真正有趣的开始...如果你想让这个自定义TabControl具有设计时功能。但是,你现在真的有更好的生活方式吗?如果你花了五秒多的时间来回答这个问题,你绝对需要创建自己的TabControl:)
Since a TabControl, by definition, is a one-at-a-time viewer, which is equivalent, logically, to being able to make only one radio-button in a group of radio-buttons the active/selected radio-button: why do you want to do this ?

The FireFox-like TabControl you cite uses what appears to be a CheckBox to trigger a drop-down menu.

The TabControl itself is "locked down tight" in terms of adding Controls: you can only add TabPages to the TabControl, itself, and only add Controls to an individual TabPage. To my knowledge, you can't create a custom TabControl with custom Tabs, by using inheritance, unless you do all the drawing/painting yourself (OwnerDrawn) ... that's a major piece of work.

There are several articles on CP that will show you how to create an OwnerDrawn TabControl with custom Tabs, for example: "Painting Your Own Tabs - Second Edition"[^].

There is an alternative, though, if you have the motivation, and the time: develop your own custom TabControl from scratch. Here's how I would proceed:

1. create a UserControl that would serve as the "master container" for all the custom TabPages.

2. create a UserControl that will serve as the "template" for each rectangular TabPage.

3. create a UserControl with a custom region (defined by use of a GraphicsPath and setting the region of the UserControl) that has the Tab shape you want, and will serve as the "template" for all Tabs. If you wanted to get "fancy" and have different shaped Tabs for the first Tab, or last Tab, then define additional UserControl templates. On the custom Tab: place whatever Controls you want (CheckBox, RadioButton, ComboBox).

4. implement the necessary 'Add method (emulating the TabControl in WinForms) that will add a new instances of the UserControls developed in steps #2~3 to the master container UserControl #1, and adjust the x-axis position of the custom Tab UserControl #3 in relation to the TabPage UserControl template #2 so that you achieve the look-and-feel of a standard TabControl.

And then, the real fun begins ... if you want to make this custom TabControl have design-time functionality. But, do you really have anything better to do with your life right now ? If you took more than five seconds to answer that question, you absolutely need to create your own TabControl :)


Hello Bill!感谢您的回答。



现在我就像你伤心一样:活动TabPage意味着它被检查。但我认为这对用户来说有点混乱 - TabControls通常用于分组元素,而不是选择它们。



因为在我的情况下标题是静态的我可以作弊并在TabControl前面的特定位置手动创建单独的RadioButton。



我发现了一些关于TabPage的细节 - 它的标题不会自动修剪空格。因此,如果我覆盖它的Text属性可能是我将能够用几个空格扩展它并在标题的文本附近插入一个RadioButton。 GetTabRect和MeasureString会给我一个偏移量。





谢谢,比尔:)
Hello Bill! Thank you for your answer.

Right now I do it just like you sad: active TabPage means that it is "checked". But I think that it will be a little confusing to a user - TabControls are usually using for grouping elements, not selecting them.

Because in my case headers are static I can cheat a little and manually create separate RadioButtons in front of TabControl in specific locations.

I found a little detail about TabPage - it's header doesn't auto-trim spaces. So if I override it's Text property may be I will be able to expand it with a couple of spaces and insert a RadioButton near the header's text. GetTabRect and MeasureString will give me an offset.


Thanks, Bill :)


这篇关于TabPage标题自定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆