Imports System.Collections.ObjectModel
Imports System.Runtime.InteropServices
Public Class Form1
'// Function used to set Vista-theming on our listview
<DllImport("uxtheme", CharSet:=CharSet.Unicode)> _
Public Shared Function SetWindowTheme(ByVal hWnd As IntPtr, ByVal textSubAppName As String, ByVal textSubIdList As String) As Integer
End Function
'// A collection of controls that will be placed on a new panel
Dim ctrlCollection As Collection(Of Control)
'// A Collection of all our panels
Dim _Panels As Collection(Of Panel)
Public Property Panels() As Collection(Of Panel)
Get
If _Panels Is Nothing Then _Panels = New Collection(Of Panel)
Return _Panels
End Get
Set(ByVal value As Collection(Of Panel))
_Panels = value
End Set
End Property
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'// Ensure vista-theming
SetWindowTheme(lvw.Handle, "explorer", Nothing)
'// Declare a panel for later use
Dim pnl As Panel
'// Set the ImageList of the listview to the tabcontrol ImageList (so they share images)
lvw.LargeImageList = tabCtrl.ImageList
'// For each TabPage, create a new Panel
For Each tab As TabPage In tabCtrl.TabPages
'// Create new panel
pnl = New Panel
'// Set some properties
pnl.Dock = DockStyle.Fill
pnl.Visible = True
'// Add the panel to the 'background panel' controls collection so it becomes visible
pnlBackground.Controls.Add(pnl)
'// Add the panel to our Panels collection so we can keep track of it easily
Me.Panels.Add(pnl)
'// Create a new ListviewItem with the text and image from the current TabPage
Dim lvi As New ListViewItem(tab.Text)
lvi.Tag = pnl 'Important: The Tag property of the listviewitem contains the corresponding panel
lvi.ImageIndex = tab.ImageIndex
lvw.Items.Add(lvi)
'// For each control, add it to a new panel
'// 1. Add the controls to a Collection(Of Control)
ctrlCollection = New Collection(Of Control)
For Each ctrl As Control In tab.Controls
ctrlCollection.Add(ctrl)
Next
'// 2. Add the controls in the _Controls collection to the panel
For Each ctrl As Control In ctrlCollection
pnl.Controls.Add(ctrl)
Next
Next
'// Hide tabcontrol
tabCtrl.Visible = False
End Sub
Private Sub lvw_ItemSelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles lvw.ItemSelectionChanged
'// Hide every panel first
For Each _panel As Panel In Panels
_panel.Visible = False
Next
'// Get the panel from the Tag property of the currently selected item and make it visible
Dim pnl As Panel = CType(e.Item.Tag, Panel)
pnl.Visible = True
End Sub
End Class