Public Class ComboboxTree Inherits ComboBox
Private Const WM_LBUTTONDOWN As Int32 = &H201 Private Const WM_LBUTTONDBLCLK As Int32 = &H203 Private m_TreeViewHost As ToolStripControlHost Private m_DropDown As ToolStripDropDown
Private WithEvents TreeViewF As TreeViewForm Public Event AddNode(ByVal Node As TreeNode) Public Event DelNode(ByVal Node As TreeNode) Public Event NodeUp(ByVal Node As TreeNode) Public Event NodeDown(ByVal Node As TreeNode)
Public Sub New()
TreeViewF = New TreeViewForm(New Size(DropDownWidth, DropDownHeight)) m_TreeViewHost = New ToolStripControlHost(TreeViewF) m_DropDown = New ToolStripDropDown() With m_DropDown .AutoSize = False .Width = Me.Width .Height = 113
.Items.Add(m_TreeViewHost) End With End Sub
Private Sub TreeView_ChangeSize(ByVal NewSize As System.Drawing.Size) Handles TreeViewF.ChangeSize If NewSize.Width < Me.Width Then NewSize.Width = Me.Width If NewSize.Height < 113 Then NewSize.Height = 113 m_DropDown.Width = NewSize.Width m_DropDown.Height = NewSize.Height
m_TreeViewHost.Size = New Size(NewSize.Width - 2, NewSize.Height - 5) End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) If (m.Msg = WM_LBUTTONDBLCLK Or m.Msg = WM_LBUTTONDOWN) Then ShowDropDown() Return End If
MyBase.WndProc(m) End Sub
Private Sub ShowDropDown()
If Me.DroppedDown = False Then m_DropDown.Width = Me.Width m_DropDown.Height = 113
m_TreeViewHost.Size = New Size(DropDownWidth - 2, DropDownHeight + 2) m_DropDown.Show(Me, 0, Me.Height) End If End Sub⾃定义的属性和事件两个内部类end class
四个按钮的功能代码要⾃⾏写,可参照我的《移动treeview内的节点》 代码对不⾜之处请提出修改意见!
因篇幅问题不能全部显示,请点此查看更多更全内容