简体   繁体   English

c#.net-制表符页边距

[英]c# .NET - Tabpage margin

I have a tabcontrol with 3 tabpages. 我有一个带有3个选项卡的选项卡控件。 I need to add a left margin to the first tabpage ( so move all tabpages move right of 200px ). 我需要在第一个标签页上添加一个左边距(因此将所有标签页向右移动200px)。 How can I do it?? 我该怎么做??

Using Visual Studio 2008 / c# 使用Visual Studio 2008 / C#

EDIT Reading again I think you're more looking for the controls on each page to be on the right of the tabs rather than moving the buttons. 编辑再读一遍,我认为您是在寻找每个页面上的控件都在选项卡的右侧,而不是移动按钮。

As Hans suggests a panel would be the easiest way. 正如汉斯(Hans)所言,小组讨论是最简单的方法。 But it's not pretty. 但这并不漂亮。

    private void Form1_Load(object sender, EventArgs e)
    {
        // Create spacer tab with a name long enough to reach the 200px mark
        TabPage spacer = new TabPage("..............................................................");
        tabControl1.TabPages.Insert(0, spacer);

        // Create a panel at the same location of the tab control.
        Panel spacerBlock = new Panel();
        spacerBlock.Name = "spacer";
        spacerBlock.Location = tabControl1.Location;
        spacerBlock.Width = 198;
        spacerBlock.Height = 20;

        this.Controls.Add(spacerBlock);

        spacerBlock.BringToFront();
    }

    private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Ensure the user can't use the keyboard to somehow select the spacer tab.
        if (tabControl1.SelectedIndex == 0)
            tabControl1.SelectedIndex = 1;

        // Check if the second (first I guess) tab is selected and adjust the panel to keep the look consistant.
        if (tabControl1.SelectedIndex == 1)
            this.Controls["spacer"].Width = 198;
        else
            this.Controls["spacer"].Width = 200;
    }

You'll want to make sure the tab isn't selectable by the user via keyboard shortcuts thus the index change check. 您需要确保用户无法通过键盘快捷键选择选项卡,从而无法检查索引更改。

Also note the panel will have to have its width adjusted if the second (first in your case) tab is selected due to the 3d GUI effect. 还要注意,如果由于3d GUI效果而选择了第二个(在您的情况下为第一个)选项卡,则必须调整面板的宽度。

Honestly the hassle of taking into account the appearance settings of the end user to ensure the spacer tab's text and the panel width are correct length doesn't really make up for fancy look IMHO. 老实说,考虑到最终用户的外观设置以确保间隔标签的文本和面板宽度正确的长度并不能真正弥补IMHO的麻烦。

Only other option I could think of would be a tab panel with a 16px height. 我能想到的唯一其他选项是高度为16px的选项卡面板。 Again this would have to be adjusted depending on the end users appearance settings, not to mention the excess overhead in getting it all working. 同样,这必须根据最终用户的外观设置进行调整,更不用说使所有功能正常工作的额外开销。

If it's the AjaxControlToolkit tab control, add this CSS class: 如果是AjaxControlToolkit选项卡控件,请添加以下CSS类:

.TabContainer .ajax__tab_header
{
    padding-left: 200px;
}

you would need a work-around for that because tab pages can't be moved. 您将需要一种解决方法,因为无法移动标签页。 You might wanna place a groupbox inside the tabpage and then you can add all the controls inside the groupbox as you desire... 您可能想在选项卡页面中放置一个分组框,然后可以根据需要在该分组框内添加所有控件...

// tabPage 1
this.tabPage1.Controls.Add(this.groupBox1);

// groupBox1
this.groupBox1.Location = new System.Drawing.Point(200,6);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.AnyControls); //etc

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

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