Is there any way to make the size of the tab control expand in both hight and width when the entire window is resized? For example, if I initially set the top of the tab control to be about 1 inch below the top of the window and fill the rest of the window I'd like the top to remain where I put it when the window is resized.

Hi,

There isn't a property for that, but you can use this in the Form load event:

 TabControl1.Dock = DockStyle.Fill

Anchor won't work since you don't want the tabcontrol right to the top, and dockstyle.fill won't work for the same reason.

Here's one way:

In the designer, size the control to reach the bottom of the form and have the top where you want it. Set the dock property to bottom.

In the code, declare a class level variable as location, then set it to the tabcontrol location in the form load handler.

In the form's resize event you can use this to set the size of the tabcontrol. With the dock set to bottom, changing the size will put the top back where you want it:

Public Class Form2
    Dim TCOffset As Point
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitializeComponent()
        TCOffset = TabControl1.Location
    End Sub

    Private Sub Form2_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        TabControl1.Size = New Size(Me.ClientSize.Width, Me.ClientSize.Height - TCOffset.Y)
    End Sub
End Class

With this there is a flicker as the tabcontrol resizes with the form, but the top does stay in the same place. You could also use the ReseizeEnd event but the tabcontrol won't resize until the form resize has finished and it has the effect of snapping into place.

Edited 3 Years Ago by tinstaafl

Comments
thanks

That's great -- almost what I want. Instead of ResizeEnd just set Resize event handler so that the top of the tab control stays in place while I'm resizing the form. Now to do the same with the other controls on the form.

calling InitializeComponent() turns off the event handlers for other events such as the click event for buttons, how to reset those event handlers?

Edited 3 Years Ago by Ancient Dragon

I finally got it to work correctly. I moved InitializeComponent() into a New constructor then added global boolean IsInitialized to prevent the Resize event from doing anything until after the form has been completly initialized. Now the click event for the button works and the top of the tab control stays in place while resizing the form.

Public Class Form1
    Dim TCOffset As Point
    Dim IsResized As Boolean = False

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TCOffset = TabControl1.Location
        IsResized = True
    End Sub

    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
        If IsResized = True Then
            TabControl1.Size = New Size(Me.ClientSize.Width, Me.ClientSize.Height - TCOffset.Y)
        End If
    End Sub

    Private Sub btnGo_Click(sender As Object, e As EventArgs) Handles btnGo.Click
        Dim WebPage As String = Trim(txtAddress.Text)
        Me.WebBrowser1.Navigate(WebPage)

    End Sub


End Class
This question has already been answered. Start a new discussion instead.