UnbreakableMystic
UnbreakableMystic

Reputation: 176

How do I place the button besides the tab?

I have this C# winform with tabs on toolstrip. I need to place that plus button on extreme right "+" besides the latest tab on toolstrip. I have tried for location, but couldn't get it. Is there any other way to do this. The button should shift its position based on the new tab added or deleted

Upvotes: 0

Views: 90

Answers (1)

TaW
TaW

Reputation: 54433

Here is a solution that uses a workaround: It owner-draws the Tab control in order to get the Bounds of each Tab..:

enter image description here

private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
{
    var page = tabControl.TabPages[e.Index];
    e.DrawBackground();
    e.DrawFocusRectangle();
    TextRenderer.DrawText(e.Graphics, page.Text, page.Font, e.Bounds, e.ForeColor);

    if (e.Index == tabControl.TabCount - 1)
        button6.Left = tabControl.Left + e.Bounds.Right + 3;
}

private void buttonAdd_Click(object sender, EventArgs e)
{
    tabControl.TabPages.Add("new page " + tabControl.TabCount);
}
private void buttonRemoveLast_Click(object sender, EventArgs e)
{
    tabControl.TabPages.RemoveAt(tabControl.TabCount - 1);
}

You may want to change the owner-drawing to suit your application.. There a are quite a few examples around.

Upvotes: 1

Related Questions