在我的 TabControls 中添加新的 TabPage 时,我希望它自动调整为 Form1 的当前高度/宽度。我可以在表单加载上做到这一点。但是,当我添加一个新选项卡然后调整窗口大小时,它什么也不做。感谢您提供任何有用的意见。
导入 System.IO 公共类 Form1
'The Global Variables
Dim theControls As New theControls
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'For Auto Sizing theControls to Form1
TabPage1.Controls.Add(theControls)
theControls.theBrowser.Navigate("http://google.com")
End Sub
Private Sub Form1_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
'For Auto Sizing theControls to Form1
Me.TabControl1.Width = Me.Width - 20
Me.TabControl1.Height = Me.Height
theControls.Width = Me.TabControl1.Width - 20
theControls.Height = Me.TabControl1.Height - 20
End Sub
Private Sub TabControl1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.Click
'Add new tab with the same controls.
Dim theNewTab As New TabPage
Dim theOtherControls As New theControls
Dim theTabCounter As Integer = TabControl1.TabPages.Count
Dim theSelectedTab As String = TabControl1.SelectedTab.Text
If theSelectedTab = "+" Then
TabControl1.TabPages.Insert(theTabCounter - 1, theNewTab)
theNewTab.Controls.Add(theOtherControls)
theControls.theBrowser.Navigate("http://google.com")
theOtherControls.theBrowser.Navigate("http://google.com")
TabControl1.SelectTab(theTabCounter - 1)
End If
End Sub
结束类
tabPageCounter 变量可以忽略。我开始认为需要一个 For Each 循环,但我认为有一种更简单的方法。从我在网上找到的内容来看,我已经了解了这个 Dock 功能,但我想我不太清楚如何使用它......