Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 在TabPage的每个实例中调整UserControls的大小_Vb.net_Browser_User Controls_Tabcontrol - Fatal编程技术网

Vb.net 在TabPage的每个实例中调整UserControls的大小

Vb.net 在TabPage的每个实例中调整UserControls的大小,vb.net,browser,user-controls,tabcontrol,Vb.net,Browser,User Controls,Tabcontrol,这件事已经折磨了我好几个星期了。我有一个我制作的浏览器,它使用一个TabControl。每次单击选项卡页“+”时,都会添加一个新的选项卡页。每个选项卡页都有用户控件(WebBrowser、地址栏、后退按钮、前进按钮等)。当用户调整Form1的大小时,我希望所有UserControl都适合选项卡Page/Form1 基本上,我希望我的userControls适合表单的当前大小,但我无法理解。现在,我让TabControls工作,但这是通过简单地使用Anchor属性完成的。该选项不适用于UserCo

这件事已经折磨了我好几个星期了。我有一个我制作的浏览器,它使用一个TabControl。每次单击选项卡页“+”时,都会添加一个新的选项卡页。每个选项卡页都有用户控件(WebBrowser、地址栏、后退按钮、前进按钮等)。当用户调整Form1的大小时,我希望所有UserControl都适合选项卡Page/Form1

基本上,我希望我的userControls适合表单的当前大小,但我无法理解。现在,我让TabControls工作,但这是通过简单地使用Anchor属性完成的。该选项不适用于UserControls。我通过编程手动定位了它,但它没有调整大小。它只是把所有东西都放在中间,尺寸越小…… 代码如下:

'这是表单的代码

导入System.IO 公开课表格1

'The Global Variables
Dim theControls1 As New theControls


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    TabPage1.Controls.Add(theControls1)
    theControls1.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

    theControls1.Width = TabControl1.Width - 8
    theControls1.Height = TabControl1.Height - 25
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

    theOtherControls.AutoSize = True
    theOtherControls.Width = TabControl1.Width
    theOtherControls.Height = TabControl1.Height

    theOtherControls.Anchor = AnchorStyles.Right & AnchorStyles.Left & AnchorStyles.Bottom & AnchorStyles.Top



    Dim theSelectedTab As String = TabControl1.SelectedTab.Text

    If theSelectedTab = "+" Then
        TabControl1.TabPages.Insert(theTabCounter - 1, theNewTab)
        theNewTab.Controls.Add(theOtherControls)
        theControls1.theBrowser.Navigate("http://google.com")
        theOtherControls.theBrowser.Navigate("http://google.com")
        TabControl1.SelectTab(theTabCounter - 1)
    End If
End Sub
末级

'这是USERCONTROLS的代码

导入System.IO 导入System.Data.OleDb 公共类控制

'The History Database Connection String 
Dim theHistoryDatabaseConn As New OleDbConnection

Private Sub ComboBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles theAddressBar.KeyDown
    'Navigate to Webpage stated in theAddressBar
    If e.KeyValue = Keys.Enter Then
        theBrowser.Navigate(theAddressBar.Text)
        e.SuppressKeyPress = True
    End If
End Sub

Private Sub goForward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goForward.Click
    theBrowser.GoForward()
End Sub

Private Sub goBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles goBack.Click
    theBrowser.GoBack()
End Sub

Private Sub theBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles theBrowser.DocumentCompleted

    'Set Tab Text to current web page and Address Bar
    Form1.TabControl1.SelectedTab.Text = theBrowser.Url.Host.ToString
    Me.theAddressBar.Text = Me.theBrowser.Url.AbsoluteUri.ToString

    'Read the History
    theHistoryDatabaseConn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Marc Wilson\Documents\Visual Studio 2010\Projects\myBrowser\myBrowser\bin\Debug\TheHistoryDB.accdb"
    theHistoryDatabaseConn.Open()


    'Populate theAddressBar with the contents from the History 
    theAddressBar.Items.Clear()
    Dim readTheHistory As String
    Dim getTheHistory As OleDbCommand
    readTheHistory = "SELECT [Host Name] FROM TheHistory"
    getTheHistory = New OleDbCommand(readTheHistory, theHistoryDatabaseConn)
    Dim theData As New OleDbDataAdapter(getTheHistory)
    Dim theTable As New DataTable("TheHistory")
    'theHistoryDatabaseConn.Open()
    theData.Fill(theTable)
    For Each row As DataRow In theTable.Rows
        theAddressBar.Items.Add(row.Item("Host Name"))
    Next




    'Writes history to TheHistory Database (No Duplicates!)
    If theAddressBar.Items.Contains(theBrowser.Url.Host.ToString) Then
    Else

        'Write The History
        Dim writeTheHistory As OleDbCommand = New OleDbCommand("INSERT INTO TheHistory ([Host Name], [Absolute Path]) VALUES (theBrowser.URL.Host.ToString, theBrowser.URL.AbsoluteUri.ToString)", theHistoryDatabaseConn)
        writeTheHistory.Parameters.Add("@Host Name", OleDbType.Char, 255).Value = theBrowser.Url.Host.ToString
        writeTheHistory.Parameters.Add("@Absolute Path", OleDbType.Char, 255).Value = theBrowser.Url.AbsoluteUri.ToString

        theHistoryDatabaseConn.Close()


        theHistoryDatabaseConn.Open()
        writeTheHistory.ExecuteNonQuery()
        theHistoryDatabaseConn.Close()
    End If
    theHistoryDatabaseConn.Close()
End Sub

Private Sub theBrowser_ProgressChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles theBrowser.ProgressChanged

    'Status Bar Text
    Label1.Text = theBrowser.StatusText.ToString
End Sub

Private Sub theAddressBar_SelectedValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles theAddressBar.SelectedValueChanged
    Me.theBrowser.Navigate(Me.theAddressBar.Text)
End Sub

无论何时创建UserControl实例,都要将其Dock()属性设置为Fill:

Dim theOtherControls As New theControls
theOtherControls.Dock = DockStyle.Fill

无论何时创建UserControl实例,请将其Dock()属性设置为Fill:

Dim theOtherControls As New theControls
theOtherControls.Dock = DockStyle.Fill

只需将控件的Dock属性设置为Fill,即可自动填充整个选项卡页面。只需将控件的Dock属性设置为Fill,即可自动填充整个选项卡页面。