Search code examples
vb.netresizetabpage

Automatically resize tabpage on tab click (VB.NET)


I would like my tabpage (and dialog) to resize when the tab is clicked.

For example:

  • Tab1 is 300x200
  • Tab2 is 400x400

The dialog opens in Tab1 in 300x200. When you click Tab2, the dialog and tabpage resizes to 400x400.


Solution

  • Set the Dock() property of the TabControl to Fill, then handle the SelectedIndexChanged() event:

    Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
        Select Case TabControl1.SelectedIndex
            Case 0
                Me.Size = New Size(300, 200)
            Case 1
                Me.Size = New Size(400, 400)
        End Select
    End Sub