VB.Net Tutorial/GUI/Splitter

Материал из VB Эксперт
Перейти к: навигация, поиск

Splitter Control

Imports System.Windows.Forms
public class SplitterControl
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    Private components As System.ruponentModel.IContainer
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents Splitter2 As System.Windows.Forms.Splitter
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Splitter3 As System.Windows.Forms.Splitter
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ruponents = New System.ruponentModel.Container
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.TreeView1 = New System.Windows.Forms.TreeView
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.ruponents)
        Me.Splitter2 = New System.Windows.Forms.Splitter
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Label1 = New System.Windows.Forms.Label
        Me.Splitter3 = New System.Windows.Forms.Splitter
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        "
        "Splitter1
        "
        Me.Splitter1.Location = New System.Drawing.Point(0, 0)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 266)
        Me.Splitter1.TabIndex = 0
        Me.Splitter1.TabStop = False
        "
        "TreeView1
        "
        Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left
        Me.TreeView1.Location = New System.Drawing.Point(3, 0)
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("A", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Visual Basic"), New System.Windows.Forms.TreeNode("Visual C++"), New System.Windows.Forms.TreeNode("Delphi"), New System.Windows.Forms.TreeNode("Java")}), New System.Windows.Forms.TreeNode("B", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("1"), New System.Windows.Forms.TreeNode("2"), New System.Windows.Forms.TreeNode("3"), New System.Windows.Forms.TreeNode("4")})})
        Me.TreeView1.Size = New System.Drawing.Size(101, 266)
        Me.TreeView1.TabIndex = 1
        "
        "Splitter2
        "
        Me.Splitter2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Splitter2.Location = New System.Drawing.Point(104, 0)
        Me.Splitter2.Name = "Splitter2"
        Me.Splitter2.Size = New System.Drawing.Size(8, 266)
        Me.Splitter2.TabIndex = 2
        Me.Splitter2.TabStop = False
        "
        "Panel1
        "
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.Panel1.Controls.Add(Me.ListView1)
        Me.Panel1.Controls.Add(Me.Splitter3)
        Me.Panel1.Controls.Add(Me.Label1)
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Panel1.Location = New System.Drawing.Point(112, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(248, 264)
        Me.Panel1.TabIndex = 3
        "
        "Label1
        "
        Me.Label1.Dock = System.Windows.Forms.DockStyle.Top
        Me.Label1.Location = New System.Drawing.Point(0, 0)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(244, 32)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "Label1"
        "
        "Splitter3
        "
        Me.Splitter3.Dock = System.Windows.Forms.DockStyle.Top
        Me.Splitter3.Location = New System.Drawing.Point(0, 32)
        Me.Splitter3.Name = "Splitter3"
        Me.Splitter3.Size = New System.Drawing.Size(244, 8)
        Me.Splitter3.TabIndex = 1
        Me.Splitter3.TabStop = False
        "
        "ListView1
        "
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.Location = New System.Drawing.Point(0, 40)
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(244, 220)
        Me.ListView1.TabIndex = 2
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(360, 266)
        Me.Controls.Add(Me.Panel1)
        Me.Controls.Add(Me.Splitter2)
        Me.Controls.Add(Me.TreeView1)
        Me.Controls.Add(Me.Splitter1)
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
    Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
        Dim childnum, index, i As Int32
        childnum = TreeView1.SelectedNode.GetNodeCount(False)
        index = TreeView1.SelectedNode.Index
        index = index + 1
        ListView1.Items.Clear()
        For i = 0 To childnum - 1
            ListView1.Items.Add(index.ToString + "." + i.ToString, 1)
        Next
        Label1.Text = TreeView1.SelectedNode.FullPath
    End Sub
End Class

Use Spliter

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class UseSpliter
   public Shared Sub Main
        Application.Run(New frmMultipane)
   End Sub
End class
Public Class frmMultipane
    Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()
        "This call is required by the Windows Form Designer.
        InitializeComponent()
        "Add any initialization after the InitializeComponent() call
    End Sub
    "Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub
    "Required by the Windows Form Designer
    Private components As System.ruponentModel.IContainer
    "NOTE: The following procedure is required by the Windows Form Designer
    "It can be modified using the Windows Form Designer.  
    "Do not modify it using the code editor.
    Friend WithEvents TreeView1 As System.Windows.Forms.TreeView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.ruponents = New System.ruponentModel.Container()
        Me.TreeView1 = New System.Windows.Forms.TreeView()
        Me.Splitter1 = New System.Windows.Forms.Splitter()
        Me.Panel1 = New System.Windows.Forms.Panel()
        Me.ListView1 = New System.Windows.Forms.ListView()
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        "
        "TreeView1
        "
        Me.TreeView1.Dock = System.Windows.Forms.DockStyle.Left
        Me.TreeView1.Name = "TreeView1"
        Me.TreeView1.SelectedImageIndex = -1
        Me.TreeView1.Size = New System.Drawing.Size(200, 221)
        Me.TreeView1.TabIndex = 0
        "
        "Splitter1
        "
        Me.Splitter1.Location = New System.Drawing.Point(200, 0)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(8, 221)
        Me.Splitter1.TabIndex = 1
        Me.Splitter1.TabStop = False
        "
        "Panel1
        "
        Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListView1})
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.Panel1.Location = New System.Drawing.Point(208, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(192, 221)
        Me.Panel1.TabIndex = 2
        "
        "ListView1
        "
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(192, 221)
        Me.ListView1.TabIndex = 0
        "
        "frmMultipane
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(400, 221)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1, Me.Splitter1, Me.TreeView1})
        Me.Name = "frmMultipane"
        Me.Text = "Multi-Pane Example"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        TreeView1.ShowPlusMinus = True
        TreeView1.Sorted = True
        TreeView1.ShowLines = True
        Dim aNode As New TreeNode("c:\")
        aNode.Tag = "c:\"
        TreeView1.Nodes.Add(aNode)
    End Sub
    Private Sub getDirs(ByVal sender As Object, ByVal e As TreeViewEventArgs)Handles TreeView1.AfterSelect
        If Not e.Node.Nodes.Count = 0 Then Exit Sub
        Dim directory As New System.IO.DirectoryInfo(e.Node.Tag.ToString())
        getFiles(directory)
        Dim directories As System.IO.DirectoryInfo()
        directories = directory.GetDirectories()
        For Each directory In directories
            Dim aTreenode As New TreeNode(directory.Name)
            aTreenode.Tag = directory.FullName
            e.Node.Nodes.Add(aTreenode)
        Next
        e.Node.Expand()
    End Sub
    
    Sub getFiles(ByVal directory As System.IO.DirectoryInfo)
        ListView1.Columns.Clear()
        ListView1.Items.Clear()
        ListView1.View = View.Details
        ListView1.Columns.Add("Filename", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Extension", 50, HorizontalAlignment.Left)
        ListView1.Columns.Add("Bytes", 50, HorizontalAlignment.Right)
        Dim files() As System.IO.FileInfo = directory.GetFiles
        Dim file As System.IO.FileInfo
        For Each file In files
            Dim li As New ListViewItem(file.Name)
            li.SubItems.Add(file.Extension)
            li.SubItems.Add(file.Length)
            ListView1.Items.Add(li)
        Next
    End Sub
End Class