I
I
InDevo2015-01-01 18:55:30
Visual Basic
InDevo, 2015-01-01 18:55:30

Managed tabs like in Microsoft Excel?

Hello, Happy New Year. Who can suggest or give examples on how to make managed tabs in Visual Studio in Basic the way it is implemented in Excel? When you click on the "+" a new tab appears, and the "+" itself is shifted to the next position relative to the new tab and, accordingly, if possible, RMB-> Delete tab.
Excel:
cef46365372e4999982d12654bed4d34.pngVS Studio Basic:
21f6ff4d3e004b2fbda5dd2e21c9c1dc.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
KriBetko, 2015-01-01
@InDevo

On the form: TabControl - TabControl1, ContextMenuStrip - ContextMenuStrip1 with Delete item

Private Sub TabControl1_Selected(sender As Object, e As TabControlEventArgs) Handles TabControl1.Selected 'событие Selected при выборе вкладки
        If (e.TabPage.Text = "+") Then 'если вкладка имеет текст +
            e.TabPage.Text = "TabPage" + TabControl1.TabPages.Count.ToString() 'переименовываем текущую вкладку
            TabControl1.TabPages.Add("+") 'добавляем новую вкладку
        End If
    End Sub

    Private Sub TabControl1_MouseUp(sender As Object, e As MouseEventArgs) Handles TabControl1.MouseUp 'событие MouseUp при клике на TabControl1
        If (e.Button = MouseButtons.Right) Then 'Если нажатие ПКМ
            ContextMenuStrip1.Show(MousePosition, ToolStripDropDownDirection.Right) 'выводим по координатам клика ContextMenuStrip1 
        End If
    End Sub

    Private Sub DeleteToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DeleteToolStripMenuItem.Click 'событие Click при нажатии на кнопку Delete в ContextMenuStrip1
        TabControl1.TabPages.Remove(TabControl1.SelectedTab) 'Удаляем ОТКРЫТУЮ вкладку
    End Sub

The toaster doesn't know about the existence of VB and the code highlighting is a bit wrong

I
InDevo, 2015-01-02
@InDevo

Thank you very much for your reply. There is one more nuance - after adding the 3rd tab, the ones following it change the background to the one when the object is inactive. Is this how it should be or do I need to set something in the properties of the TabControl?

spoiler
b6438f102ef24b0f863f74614377ed03.jpg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question