当我的TabControls中添加了一个新的TabPage时,我希望它自动调整为Form1的当前高度/宽度。我可以在Form Load上执行此操作。但是,当我添加一个新选项卡然后调整窗口大小时,它什么都不做。感谢您提供任何有用的意见。
导入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功能,但我想我不清楚如何使用它......
答案 0 :(得分:0)
在Form_sizechanged事件中执行..
Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
Me.TabControl1.Width = Me.Width - 20
myUserControl.Width = Me.TabControl1.Width -20
End Sub