Form1.vb
资源名称:combobox.zip [点击查看]
上传用户:hbmarket
上传日期:2022-08-01
资源大小:45k
文件大小:8k
源码类别:
组合框控件
开发平台:
Visual Basic
- Public Class Form1
- 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.ComponentModel.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 ComboBoxTree1 As ComboBoxTree_Demo.Controls.ComboBoxTree
- Friend WithEvents Button2 As System.Windows.Forms.Button
- Friend WithEvents Button1 As System.Windows.Forms.Button
- Friend WithEvents Label1 As System.Windows.Forms.Label
- Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
- Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
- <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
- Me.components = New System.ComponentModel.Container
- Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
- Me.ComboBoxTree1 = New ComboBoxTree_Demo.Controls.ComboBoxTree
- Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
- Me.Button2 = New System.Windows.Forms.Button
- Me.Button1 = New System.Windows.Forms.Button
- Me.Label1 = New System.Windows.Forms.Label
- Me.TextBox1 = New System.Windows.Forms.TextBox
- Me.SuspendLayout()
- '
- 'ComboBoxTree1
- '
- Me.ComboBoxTree1.ImageList = Me.ImageList1
- Me.ComboBoxTree1.Location = New System.Drawing.Point(24, 16)
- Me.ComboBoxTree1.Name = "ComboBoxTree1"
- Me.ComboBoxTree1.SelectedImageIndex = 0
- Me.ComboBoxTree1.SelectedNode = Nothing
- Me.ComboBoxTree1.Size = New System.Drawing.Size(344, 22)
- Me.ComboBoxTree1.TabIndex = 0
- '
- 'ImageList1
- '
- Me.ImageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit
- Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
- Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
- Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
- '
- 'Button2
- '
- Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System
- Me.Button2.Location = New System.Drawing.Point(384, 48)
- Me.Button2.Name = "Button2"
- Me.Button2.Size = New System.Drawing.Size(136, 24)
- Me.Button2.TabIndex = 6
- Me.Button2.Text = "Clear Selection"
- '
- 'Button1
- '
- Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
- Me.Button1.Location = New System.Drawing.Point(384, 16)
- Me.Button1.Name = "Button1"
- Me.Button1.Size = New System.Drawing.Size(136, 24)
- Me.Button1.TabIndex = 5
- Me.Button1.Text = "Get Selected Node"
- '
- 'Label1
- '
- Me.Label1.Location = New System.Drawing.Point(24, 56)
- Me.Label1.Name = "Label1"
- Me.Label1.Size = New System.Drawing.Size(328, 16)
- Me.Label1.TabIndex = 8
- Me.Label1.Text = "Current Selection:"
- '
- 'TextBox1
- '
- Me.TextBox1.Location = New System.Drawing.Point(24, 72)
- Me.TextBox1.Name = "TextBox1"
- Me.TextBox1.ReadOnly = True
- Me.TextBox1.Size = New System.Drawing.Size(344, 20)
- Me.TextBox1.TabIndex = 7
- Me.TextBox1.Text = ""
- '
- 'Form1
- '
- Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
- Me.ClientSize = New System.Drawing.Size(536, 286)
- Me.Controls.Add(Me.Label1)
- Me.Controls.Add(Me.TextBox1)
- Me.Controls.Add(Me.Button2)
- Me.Controls.Add(Me.Button1)
- Me.Controls.Add(Me.ComboBoxTree1)
- Me.Name = "Form1"
- Me.Text = "ComboBoxTree Demo"
- Me.ResumeLayout(False)
- End Sub
- #End Region
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' Set some initial TreeView properties
- ComboBoxTree1.TreeView.ShowLines = False
- ComboBoxTree1.SuspendLayout()
- ComboBoxTree1.TreeView.Visible = True
- ' Creating the tree nodes while the TreeView is visible avoids the bug
- ' that shows a horizontal scrollbar on the bottom of the tree.
- Dim Node As TreeNode = ComboBoxTree1.TreeView.Nodes.Add("--- No selection ---")
- Node.ImageIndex = 2
- Node.SelectedImageIndex = 2
- ComboBoxTree1.TreeView.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node2"), New System.Windows.Forms.TreeNode("Node3")}), New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5")})})
- ComboBoxTree1.TreeView.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node2"), New System.Windows.Forms.TreeNode("Node3")}), New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5")})})
- ComboBoxTree1.TreeView.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node1", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("Node2"), New System.Windows.Forms.TreeNode("Node3")}), New System.Windows.Forms.TreeNode("Node4"), New System.Windows.Forms.TreeNode("Node5")})})
- ComboBoxTree1.TreeView.Visible = False
- Node = ComboBoxTree1.TreeView.Nodes.Add("New node...")
- Node.ImageIndex = 3
- Node.SelectedImageIndex = 3
- ComboBoxTree1.ResumeLayout()
- ' Select a node...
- Me.ComboBoxTree1.SelectedNode = Me.ComboBoxTree1.TreeView.Nodes.Item(2).Nodes.Item(1)
- End Sub
- Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
- ' Actually, this should be handled by the ComboBoxTree itself,
- ' but the current version of the control does not handle this.
- Me.ComboBoxTree1.DroppedDown = False
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- If Me.ComboBoxTree1.SelectedNode Is Nothing Then
- MsgBox("No tree node is selected.")
- Else
- MsgBox(Me.ComboBoxTree1.SelectedNode.Text)
- End If
- End Sub
- Private Sub ComboBoxTree1_AfterSelect(ByVal sender As Object) Handles ComboBoxTree1.AfterSelect
- If Me.ComboBoxTree1.SelectedNode Is Nothing Then
- Me.TextBox1.Text = "No tree node is selected."
- ElseIf Me.ComboBoxTree1.SelectedNode.Text.StartsWith("---") Then
- Me.ComboBoxTree1.SelectedNode = Nothing
- Else
- Me.TextBox1.Text = Me.ComboBoxTree1.SelectedNode.Text
- End If
- End Sub
- Private Sub ComboBoxTree1_BeforeSelect(ByVal sender As Object, ByVal Node As System.Windows.Forms.TreeNode, ByRef Cancel As Boolean) Handles ComboBoxTree1.BeforeSelect
- If (Not Node Is Nothing) AndAlso Node.Text.StartsWith("New") Then
- Cancel = True
- Me.ComboBoxTree1.DroppedDown = False
- MsgBox(Node.Text)
- End If
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Me.ComboBoxTree1.SelectedNode = Nothing
- End Sub
- End Class