如何在tabcontrol vb.net上定位选项卡

如何在tabcontrol vb.net上定位选项卡,vb.net,winforms,tabcontrol,Vb.net,Winforms,Tabcontrol,Net,TabStrip控件 标签是左对齐或右对齐,上对齐或下对齐 我需要从选项卡控件顶部我自己的位置开始选项卡 与Internet Explorer一样,选项卡开始于HTTP地址框之后,但它将覆盖整个页面并在左侧对齐=0。要显示右对齐的选项卡 将选项卡控件添加到窗体中 将“路线”属性设置为“右侧” 将SizeMode属性设置为Fixed,以便所有选项卡的宽度相同 将ItemSize属性设置为选项卡的首选固定大小。请记住,ItemSize属性的行为就像选项卡位于顶部一样,尽管它们是右对齐的。因此

Net,TabStrip控件

标签是左对齐或右对齐,上对齐或下对齐

我需要从选项卡控件顶部我自己的位置开始选项卡


与Internet Explorer一样,选项卡开始于HTTP地址框之后,但它将覆盖整个页面并在左侧对齐=0。

要显示右对齐的选项卡

  • 将选项卡控件添加到窗体中

  • 将“路线”属性设置为“右侧”

  • 将SizeMode属性设置为Fixed,以便所有选项卡的宽度相同

  • 将ItemSize属性设置为选项卡的首选固定大小。请记住,ItemSize属性的行为就像选项卡位于顶部一样,尽管它们是右对齐的。因此,为了使选项卡更宽,必须更改“高度”属性,为了使选项卡更高,必须更改“宽度”属性

    在下面的代码示例中,宽度设置为25,高度设置为150

  • 将DrawMode属性设置为OwnerDrawFixed

  • 为TabControl的DrawItem事件定义一个处理程序,该事件从左到右呈现文本

    C#

  • 嗯,Internet Explorer不使用TabControl,它的选项卡完全是自定义绘制的。您可以通过不使用选项卡页面来模拟类似的情况,只需将TabControl设置为仅足以显示选项卡的高度即可。
    public Form1()
    {
        // Remove this call if you do not program using Visual Studio.
        InitializeComponent();
    
        tabControl1.DrawItem += new DrawItemEventHandler(tabControl1_DrawItem);
    }
    
    private void tabControl1_DrawItem(Object sender, System.Windows.Forms.DrawItemEventArgs e)
    {
        Graphics g = e.Graphics;
        Brush _textBrush;
    
        // Get the item from the collection.
        TabPage _tabPage = tabControl1.TabPages[e.Index];
    
        // Get the real bounds for the tab rectangle.
        Rectangle _tabBounds = tabControl1.GetTabRect(e.Index);
    
        if (e.State == DrawItemState.Selected)
        {
            // Draw a different background color, and don't paint a focus rectangle.
    
            _textBrush = new SolidBrush(Color.Red);
            g.FillRectangle(Brushes.Gray, e.Bounds);
        }
        else
        {
            _textBrush = new System.Drawing.SolidBrush(e.ForeColor);
            e.DrawBackground();
        }
    
        // Use our own font.
        Font _tabFont = new Font("Arial", (float)10.0, FontStyle.Bold, GraphicsUnit.Pixel);
    
        // Draw string. Center the text.
        StringFormat _stringFlags = new StringFormat();
        _stringFlags.Alignment = StringAlignment.Center;
        _stringFlags.LineAlignment = StringAlignment.Center;
        g.DrawString(_tabPage.Text, _tabFont, _textBrush, _tabBounds, new StringFormat(_stringFlags));