我的代码片段
for vb2005
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(
Me0Me.Height)
         
End If
     
End Sub


自定义的属性和事件

两个内部类

end class
 
四个按钮的功能代码要自行写,可参照我的《移动treeview内的节点》 代码
对不足之处请提出修改意见!
posted on 2007-05-27 22:55  静林悠松  阅读(2132)  评论(1编辑  收藏  举报