简体   繁体   English

如何在Winforms中的TabControl的空白区域添加一个按钮?

[英]How can I add a button to the empty area of a TabControl in Winforms?

Grabbed the images from a similar question in WPF. 从WPF中的类似问题中抓取图像。 Basically I want the extra buttons to do different things, not create or delete tabs. 基本上我希望额外的按钮做不同的事情,而不是创建或删除标签。 Actions related to the current tab which are gonna be the same for all the tabs in a single TabControl. 与当前选项卡相关的操作对于单个TabControl中的所有选项卡将是相同的。

When I try to place my buttons on that area, the visual studio designer throws my control away, back to their original position. 当我尝试将按钮放在该区域时,视觉工作室设计师将我的控制权抛弃,回到原来的位置。 It doesn't allow me to put anything there. 它不允许我把任何东西放在那里。

Can this be done? 可以这样做吗?

alt text http://www.freeimagehosting.net/uploads/92ca1b0a8c.png alt text http://www.freeimagehosting.net/uploads/92ca1b0a8c.png

alt text http://www.freeimagehosting.net/uploads/ff0d08e0ed.png alt text http://www.freeimagehosting.net/uploads/ff0d08e0ed.png

For specifically that visual experience I'd just create a separate tab with header "+" and add some logic on switching to it - so it will perform some other action instead of switching. 对于具体的视觉体验,我只是创建一个带有标题“+”的单独选项卡,并在切换到它时添加一些逻辑 - 因此它将执行一些其他操作而不是切换。 The same can be done with multiple tabs I guess. 我猜这可以用多个标签完成。

UPDATE UPDATE

Actual code for this: 实际代码:

private void TabControl1_Selecting(Object sender, TabControlCancelEventArgs e) 
{
    if (e.TabPage... /* Do check whether some of your special TabPages is being selected */)
    {
        e.Cancel = true;

        // All other TabPage-specific actions here
        ...
    }
}

So it looks like they are using a tab as a button here. 所以看起来他们在这里使用标签作为按钮。 I would imagine they have the tab controls index change event fire a new tab into the tab control and force focus to it. 我会想象他们有选项卡控件索引更改事件触发选项卡控件中的新选项卡并强制关注它。

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

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