dcsimg
Results 1 to 2 of 2
  1. #1

    Thread Starter
    Addicted Member ryanframes's Avatar
    Join Date
    Apr 2012
    Posts
    208

    VB.NET Metroframework Docking Form on Panel in Tab Page

    Hello, how to add a form in a panel inside tab page ? i use this code to do it, but when i resize my main form, the form inside tab page doesn't auto resize.
    Code:
    Public Sub showForm(ByVal frm As MetroForm)
        Dim a As New Panel
    
        For i As Integer = 0 To tabPage.TabCount - 1
            If frm.Text = tabPage.TabPages(i).Text Then
                tabPage.SelectedIndex = i
                Exit Sub
            End If
        Next
    
        a = New Panel
        tabPage.TabPages.Add("")
        tabPage.TabPages(tabPage.TabPages.Count - 1).Controls.Add(a)
        a.Dock = DockStyle.Fill
        frm.TopLevel = False
        frm.MinimizeBox = False
        frm.MaximizeBox = False
        frm.DisplayHeader = False
        frm.AutoSize = False
        frm.Dock = DockStyle.Fill
    
        tabPage.TabPages(tabPage.TabPages.Count - 1).Text = frm.Text
        a.Visible = True
        a.Name = "pnl" & frm.Name
        a.Controls.Add(frm)
        frm.Dock = DockStyle.Fill
        frm.Visible = True
        frm.BringToFront()
    
        AddHandler a.ControlRemoved, AddressOf Me.removePanel
        tabPage.SelectedIndex = tabPage.TabPages.Count - 1
        tabPage.TabPages(tabPage.TabPages.Count - 1).Name = frm.Text
    End Sub
    here's the code to remove the tab page when form is closed :
    Code:
    Private Sub removePanel(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim a As Panel = DirectCast(sender, Panel)
        For Each obj As TabPage In tabPage.TabPages
            If obj.Name = sender.Parent.Name Then
                obj.Controls(0).Dispose() 'remove form
                tabPage.TabPages.Remove(obj) 'remove tab page
                RemoveHandler a.ControlRemoved, AddressOf Me.removePanel
            End If
        Next
    End Sub
    Screenshots :
    Name:  main.jpg
Views: 145
Size:  25.1 KBName:  main resized.jpg
Views: 115
Size:  23.4 KB
    Attached Files Attached Files
    Sorry for bad english.

  2. #2
    Fanatic Member
    Join Date
    Nov 2016
    Location
    Slovenia
    Posts
    543

    Re: VB.NET Metroframework Docking Form on Panel in Tab Page

    First of all, why are you even using Panel ? From what I see you don't even need It...Just set you form to Borderstyle.None and add that in your TabPage. You're lucky, here is something from my previous projects:


    Code:
            Dim Newpage As New TabPage()
    
            frm.TopLevel = False
            frm.Dock = DockStyle.Fill
    
            'check If form is allready opened
            If Application.OpenForms().OfType(Of Form1).Any Then
    
                For Each page As TabPage In TabControl1.TabPages
    
                    If page.Text = "My page" Then
    
                        TabControl1.SelectedTab = page
    
                    End If
    
                Next page
               
            Else
    
                Newpage.Controls.Add(frm)
                Newpage.Text = "My page"
                TabControl1.Visible = True
                TabControl1.TabPages.Add(Newpage)
                frm.Show()
                TabControl1.SelectedTab = Newpage
             
            End If

    For closing you could use a label and place It on the right side as you allready have:

    Code:
          If TabControl1.TabCount <= 0 Then
    
                Lbl.Visible = False
                Exit Sub
    
            Else
                 Dim openedpage As TabPage = TabControl1.SelectedTab
                 TabControl1.TabPages.Remove(openedpage)
                 openedpage.Dispose()
            End If
    You could also Paint a close button to your Tabcontrol and handle closing of pages there, but that involves much more coding. If you're interested, PM me and I'll help you with that too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.