孤独的猫

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

重画系列:重画TreeView控件(可扩展)

 

重画系列:重画TreeView控件(可扩展)

http://www.21tx.com 20040209Blog ganenpingsohucom

最近因公司产品的需要,重写了System.Windows.Form.TreeView,使其具有更好的外观显示,可以在树结点同时显示文字,button,链接文本,。。。还可以自定义自己的显示比如所文本,如下了图所示

重画系列:重画TreeView控件(可扩展)

 

好了,让我们来看看怎么实现的吧

首先创建类OwnTreeView继承自System.Windows.Form.TreeView,需要在其中完成主要的重画功能

然后创建一虚类TreeViewColStyle,用于定制树结点的列

最后通过继承重写上面的虚类,生成显示Button的列TreeViewButtonStyle,显示链接的列TreeViewLinkTextStyle,显示一般文本的列TreeViewTextStyle

代码如下

1OwnTreeView类源代码:

#Region "实现整体TreeView重画控制"

Public Class OwnTreeView

    Inherits System.Windows.Forms.TreeView

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()

        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。

        InitializeComponent()

        ' InitializeComponent() 调用之后添加任何初始化

        Me.SetStyle(ControlStyles.UsERPaint Or ControlStyles.Selectable, True)

        'Me.SetStyle(ControlStyles.UserMouse, True)

        Me.SetStyle(ControlStyles.StandardClick Or ControlStyles.StandardDoubleClick, False)

        Me.SetStyle(ControlStyles.ResizeRedraw, True)

        Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer, True)

    End Sub

    'UserControl1 重写 dispose 以清理组件列表。

    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

    'Windows 窗体设计器所必需的

    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的

    '可以使用 Windows 窗体设计器修改此过程。

    '不要使用代码编辑器修改它。

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        components = New System.ComponentModel.Container

        m_TVColumnStyles = New ArrayList

    End Sub

#End Region

#Region "类变量定义区"

    '保存Style对象

    Private m_TVColumnStyles As ArrayList

    '触发的点击事件

    Public Event TreeViewClick(ByVal ClickNode As TreeNode, ByVal CurrentCol As Integer)

    'node.text的分隔显示符号

    Private m_Seperator As String = ","

    '列缩进距离

    Private m_Indent As Integer = Me.Indent

    '加号的大小

    Private pWid As Integer = 6

    'mousedown鼠标所在的节点

    Private SelNode As TreeNode

    'mousedown时鼠标所在的列的位置

    Private CurrentStyle As Integer

    'mousedown时鼠标所在的单元格的bounds

    Private SelNodeBound As Rectangle

    '自己的graphics对象

    Private m_graphics As Graphics = Me.CreateGraphics

    '连线的颜色

    Private m_LineColor As Color = Color.DarkGreen

    '加减号按钮外框的颜色

    Private m_PlusMinusBorderColor As Color = Color.DarkGreen

    '加减号按钮的颜色

    Private m_PlusMinusColor As Color = Color.DarkOrange

#End Region

#Region "类对外属性区"

    '设置列分隔符

    Public Property Seperator() As String

        Get

            Return Me.m_Seperator

        End Get

        Set(ByVal Value As String)

            Me.m_Seperator = Value

        End Set

    End Property

    '连线的颜色

    Public Property LineColor() As Color

        Get

            Return Me.m_LineColor

        End Get

        Set(ByVal Value As Color)

            Me.m_LineColor = Value

        End Set

    End Property

    '加减号按钮外框的颜色

    Public Property PlusMinusBorderColor() As Color

        Get

            Return Me.m_PlusMinusBorderColor

        End Get

        Set(ByVal Value As Color)

            Me.m_PlusMinusBorderColor = Value

        End Set

    End Property

    '加减号按钮的颜色

    Public Property PlusMinusColor() As Color

        Get

            Return Me.m_PlusMinusColor

        End Get

        Set(ByVal Value As Color)

            Me.m_PlusMinusColor = Value

        End Set

    End Property

#End Region

#Region "类对外方法区"

    '添加列style

    Public Sub AddTreeViewColumnStyles(ByVal ColStyle As TreeViewColStyle)

        ColStyle.ParentControl = Me

        m_TVColumnStyles.Add(ColStyle)

    End Sub

#End Region

#Region "类私有方法区"

    '重画的主要函数,实现对每个节点的bounds的分配以及value的分隔

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

        If IsNothing(Me.Nodes) Then Return

        If Me.Nodes.Count < 1 Then Return

        Dim node As TreeNode = Me.Nodes(0)

        If Not IsNothing(node) Then

            PaintNodes(e.Graphics, node)

        End If

    End Sub

    '重画的从属函数,第归实现对每个节点的bounds的分配以及value的分隔

    Private Sub PaintNodes(ByRef g As Graphics, ByRef node As TreeNode)

        '画当前节点

        If IsNothing(node) Then Return

        DrawNode(g, node)

        If node.IsExpanded Then

            '画其第一个子节点

            PaintNodes(g, node.FirstNode)

        Else

            '画加号

        End If

        '画下一个节点

        node = node.NextNode

        If IsNothing(node) Then

            Return

        Else

            PaintNodes(g, node)

        End If

    End Sub

    '根据所在节点,取得stylebounds

    Private Function GetStyleBounds(ByRef g As Graphics, ByRef node As TreeNode, ByVal StylePosition As Integer) As Rectangle

        Dim str As String = node.Text

        Dim arrstr As String() = str.Split(Me.m_Seperator)

        str = String.Join(Me.m_Seperator, arrstr, 0, StylePosition)

        Dim preSize As SizeF

        If str = "" Then

            preSize = New SizeF(0, 0)

        Else

            preSize = g.MeasureString(str, Me.Font)

        End If

        Dim nxtSize As SizeF = g.MeasureString(Me.m_Seperator & arrstr(StylePosition), Font)

        Dim bounds As Rectangle = node.Bounds

        Dim rect As Rectangle = New Rectangle(bounds.X + preSize.Width, bounds.Y, nxtSize.Width, bounds.Height)

        Return rect

    End Function

    '画给定的节点,根据不同列的style执行各自的paint方法

    '画连线和加减号

    Private Sub DrawNode(ByRef g As Graphics, ByRef node As TreeNode)

        Dim Bounds As Rectangle = node.Bounds

        '画各个列

        Dim strArr() As String = node.Text.Split(Me.m_Seperator)

        Dim i As Integer

        For i = 0 To Me.m_TVColumnStyles.Count - 1

            If i < strArr.Length Then

                Dim bound As Rectangle = Me.GetStyleBounds(g, node, i)

                CType(Me.m_TVColumnStyles(i), CustomTreeview.TreeViewColStyle).Paint(g, bound, strArr(i), Font, node.IsSelected)

            End If

        Next

        '画连线

        If Me.ShowLines Then

            Dim points() As Point

            Dim NextNode As TreeNode = node.NextNode

            If IsNothing(NextNode) Then

                points = New Point() {New Point(Bounds.X - m_Indent / 2, Bounds.Y), _

                                      New Point(Bounds.X - m_Indent / 2, Bounds.Y + Me.pWid), _

                                     New Point(Bounds.X - pWid / 2, Bounds.Y + Me.pWid)}

            Else

                points = New Point() {New Point(Bounds.X - m_Indent / 2, Bounds.Y), _

                                      New Point(Bounds.X - m_Indent / 2, Bounds.Y + Bounds.Height), _

                                     New Point(Bounds.X - m_Indent / 2, Bounds.Y + Me.pWid), _

                                     New Point(Bounds.X - pWid / 2, Bounds.Y + Me.pWid)}

                '有下一兄弟节点,就画直接之间的连线

                Dim _points() As Point = New Point() {New Point(Bounds.X - m_Indent / 2, Bounds.Y), _

                                                    New Point(Bounds.X - m_Indent / 2, NextNode.Bounds.Y)}

                DrawLines(g, _points)

            End If

            DrawLines(g, points)

        End If

        '画加减号

        If Me.ShowPlusMinus Then

            If node.GetNodeCount(True) > 0 Then

                Dim rect As Rectangle = New Rectangle(Bounds.X - (m_Indent + Me.pWid) / 2, Bounds.Y + Me.pWid / 2, pWid, pWid)

                If node.IsExpanded Then

                    '画减号

                    DrawSymble(g, rect, False)

                Else  '画加号

                    DrawSymble(g, rect, True)

                End If

            End If

        End If

    End Sub

    '根据point集合画连线

    Private Sub DrawLines(ByRef g As Graphics, ByRef Points() As Point)

        g.DrawLines(New Pen(Me.m_LineColor), Points)

    End Sub

    '画加减号

    Private Sub DrawSymble(ByRef g As Graphics, ByVal rect As Rectangle, ByVal IsPlus As Boolean)

        g.DrawRectangle(New Pen(Me.m_PlusMinusBorderColor), rect)

        g.DrawLine(New Pen(Me.m_PlusMinusColor), rect.X, rect.Y + CInt(rect.Width / 2), rect.X + rect.Width, rect.Y + CInt(rect.Width / 2))

        If IsPlus Then

            g.DrawLine(New Pen(Me.m_PlusMinusColor), rect.X + CInt(rect.Width / 2), rect.Y, rect.X + CInt(rect.Width / 2), rect.Y + rect.Height)

        End If

    End Sub

    '实现在mousedown是的更新,同时对一次完整的Click事件进行记录和控制

    Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

        MyBase.OnMouseDown(e)

        Me.Refresh()

        Dim g As Graphics = m_graphics

        Dim pointmouse As Point = (New Point(e.X, e.Y))

        Dim node As TreeNode = Me.GetNodeAt(pointmouse)

        If IsNothing(node) Then Return

        SelNode = node

        Dim strArr() As String = node.Text.Split(Me.m_Seperator)

        Dim i As Integer

        For i = 0 To Me.m_TVColumnStyles.Count - 1

            If i < strArr.Length Then

                Dim bound As Rectangle = Me.GetStyleBounds(g, node, i)

                Dim rect As Rectangle = CType(Me.m_TVColumnStyles(i), TreeViewColStyle).GetCellBounds(bound)

                If rect.Contains(pointmouse) Then

                    'RaiseEvent TreeViewClick(node, i)

                    CurrentStyle = i

                    SelNodeBound = rect

                    Exit For

                End If

            End If

        Next

    End Sub

    ''画背景颜色

    Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs)

        Dim g As Graphics = pevent.Graphics

        If IsNothing(Me.BackgroundImage) Then

            g.FillRectangle(New SolidBrush(BackColor), pevent.ClipRectangle)

        Else

            g.DrawImage(Me.BackgroundImage, pevent.ClipRectangle)

        End If

    End Sub

    ''实现在mousedown是的更新,同时判断并实现一次完整的Click事件

    Protected Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)

        MyBase.OnMouseUp(e)

        Me.Refresh()

        'Dim g As Graphics = Me.CreateGraphics

        Dim pointmouse As Point = (New Point(e.X, e.Y))

        Dim node As TreeNode = Me.GetNodeAt(pointmouse)

        If IsNothing(node) Then Return

        If SelNodeBound.Contains(pointmouse) Then

            RaiseEvent TreeViewClick(SelNode, CurrentStyle)

        End If

    End Sub

    ''实现鼠标图像变化

    Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim g As Graphics = m_graphics

        Dim pointmouse As Point = (New Point(e.X, e.Y))

        Dim node As TreeNode = Me.GetNodeAt(pointmouse)

        If IsNothing(node) Then Return

        Dim IsChangeCursor As Boolean = False

        Dim strArr() As String = node.Text.Split(Me.m_Seperator)

        Dim i As Integer

        Dim ChangedCursor As Cursor

        For i = 0 To Me.m_TVColumnStyles.Count - 1

            If i < strArr.Length Then

                Dim bound As Rectangle = Me.GetStyleBounds(g, node, i)

                Dim rect As Rectangle = CType(Me.m_TVColumnStyles(i), TreeViewColStyle).GetCellBounds(bound)

                If rect.Contains(pointmouse) Then

                    ChangedCursor = CType(Me.m_TVColumnStyles(i), TreeViewColStyle).Cursor

                    If ChangedCursor Is Cursors.Default Then

                    Else

                        IsChangeCursor = True

                        Exit For

                    End If

                End If

            End If

        Next

        If IsChangeCursor Then

            Me.Cursor = ChangedCursor

        Else

            Me.Cursor = Cursors.Default

        End If

        MyBase.OnMouseMove(e)

    End Sub

#End Region

End Class

2TreeViewColStyle类源代码:

#Region "自定义TreeViewStyle基类,所有的列style的生成必须继承它"

Public MustInherit Class TreeViewColStyle

#Region "必须重写的方法"

    ''根据给定的信息自由的画格中的显示

    Public MustOverride Overloads Sub Paint(ByRef g As Graphics, _

                                      ByVal bounds As Rectangle, _

                                      ByVal Source As String, _

                                      ByVal Font As Font, _

                                      ByVal IsSelected As Boolean)

    ''根据给定的Bounds获取到自己裁出的bounds,用于在上一级类中判断鼠标是否处于此bounds

    Public MustOverride Function GetCellBounds(ByVal Bounds As Rectangle) As Rectangle

#End Region

    '所在的treeview

    Public WithEvents ParentControl As TreeView

    '''鼠标图像的显示

    Private m_Cursor As Cursor = Cursors.Default

    Public Property Cursor() As Cursor

        Get

            Return m_Cursor

        End Get

        Set(ByVal Value As Cursor)

            m_Cursor = Value

        End Set

    End Property

End Class

#End Region

3TreeViewButtonStyle类源代码,实现双色button

#Region "自定义列style,实现双色button类型的显示"

Public Class TreeViewButtonStyle : Inherits TreeViewColStyle

#Region "类变量区"

    '判断是否鼠标按下,以显示鼠标按下的图像

    Private IsMouseDown As Boolean = False

    Private xMagin As Integer = 2

    Private yMagin As Integer = 2

    '按钮的背景色

    Private m_BackColor As Color = Color.BurlyWood

    '按钮的前景色

    Private m_ForeColor As Color = Color.White

    '按钮的样式

    Private m_Style As Style = Style.RectStyle

    '大小

    Private m_size As Size = New Size(20, 10)

    Public Enum Style

        RectStyle = 0

        EllipseStyle = 1

        CircleStyle = 2

    End Enum

#End Region

#Region "对外属性区"

    '--------------------对外属性--------------

    '亮色

    Public Property LightColor() As Color

        Get

            Return m_ForeColor

        End Get

        Set(ByVal Value As Color)

            m_ForeColor = Value

        End Set

    End Property

    '暗色

    Public Property GrayColor() As Color

        Get

            Return Me.m_BackColor

        End Get

        Set(ByVal Value As Color)

            Me.m_BackColor = Value

        End Set

    End Property

    Public Property ButtonStyle() As Style

        Get

            Return Me.m_Style

        End Get

        Set(ByVal Value As Style)

            Me.m_Style = Value

        End Set

    End Property

    '设置button的大小

    Public Property Size() As Size

        Get

            Return Me.m_size

        End Get

        Set(ByVal Value As Size)

            Me.m_size = Value

        End Set

    End Property

#End Region

#Region "类对外方法区"

    '提供上层调用,得知上层提供的bounds下的实际paintbounds

    Public Overrides Function GetCellBounds(ByVal Bounds As Rectangle) As Rectangle

        Dim rect As Rectangle

        If IsNothing(m_size) Then

            rect = Bounds

        Else

            If m_size.Width > Bounds.Width Or m_size.Height > Bounds.Height Then

                rect = Bounds

            Else

                rect = New Rectangle(Bounds.X + (Bounds.Width - m_size.Width) / 2, Bounds.Y + (Bounds.Height - m_size.Height) / 2, m_size.Width, m_size.Height)

            End If

        End If

        Return rect

    End Function

    '提供给上层调用的paint方法

    Public Overrides Sub Paint(ByRef g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal Source As String, ByVal Font As Font, ByVal IsSelected As Boolean)

        Dim rect As Rectangle = GetCellBounds(bounds)

        Dim brush As Drawing.Drawing2D.LinearGradientBrush

        Dim brush1 As Drawing.Drawing2D.LinearGradientBrush

        brush = New Drawing.Drawing2D.LinearGradientBrush(New PointF(rect.X, rect.Y), New PointF(rect.X, rect.Y + rect.Height), Me.m_ForeColor, Me.m_BackColor)

        'brush = New Drawing.Drawing2D.LinearGradientBrush(New PointF(0, 0), New PointF(0, Me.Height), m_BackColor, Me.m_ForeColor)

        If Me.IsMouseDown AndAlso rect.Contains(Me.ParentControl.PointToClient(Me.ParentControl.MousePosition)) Then

            brush1 = New Drawing.Drawing2D.LinearGradientBrush(New PointF(rect.X + xMagin, rect.Y + yMagin), New PointF(rect.X + xMagin, rect.Y + rect.Height), Color.FromArgb(0, 255, 255, 255), Color.FromArgb(150, 255, 255, 255))

        Else

            brush1 = New Drawing.Drawing2D.LinearGradientBrush(New PointF(rect.X + xMagin, rect.Y + yMagin), New PointF(rect.X + xMagin, rect.Y + rect.Height / 2), Color.FromArgb(150, 255, 255, 255), Color.FromArgb(0, 255, 255, 255))

        End If

        brush.WrapMode = Drawing.Drawing2D.WrapMode.TileFlipX

        brush1.WrapMode = Drawing.Drawing2D.WrapMode.TileFlipX

        Dim rect1 As Rectangle = New Rectangle(rect.X + xMagin, rect.Y + yMagin, rect.Width - 2 * xMagin, rect.Height / 2)

        Select Case Me.m_Style

            Case Style.RectStyle

                Me.DrawRectStyle(g, rect, rect1, brush, brush1)

            Case Style.EllipseStyle

                Me.DrawEllipseStyle(g, rect, rect1, brush, brush1)

            Case Style.CircleStyle

                Me.DrawEllipseStyle(g, rect, rect1, brush, brush1)

            Case Else

                Me.DrawRectStyle(g, rect, rect1, brush, brush1)

        End Select

    End Sub

#End Region

#Region "类私有方法区"

    '画椭圆形按钮

    Private Sub DrawEllipseStyle(ByRef g As Graphics, ByVal rect As Rectangle, ByVal rect1 As Rectangle, ByVal bbrush As Brush, ByVal fbrush As Brush)

        g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias

        g.FillEllipse(bbrush, rect)

        g.FillEllipse(fbrush, rect)

        g.DrawEllipse(New Pen(m_BackColor), rect)

    End Sub

    '画方形按钮

    Private Sub DrawRectStyle(ByRef g As Graphics, ByVal rect As Rectangle, ByVal rect1 As Rectangle, ByVal bbrush As Brush, ByVal fbrush As Brush)

        g.SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias

        g.FillRectangle(bbrush, rect)

        g.FillRectangle(fbrush, rect)

        g.DrawRectangle(New Pen(m_BackColor), rect)

    End Sub

    Private Sub XpStyleButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ParentControl.MouseDown

        IsMouseDown = True

    End Sub

    Private Sub XpStyleButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ParentControl.MouseUp

        IsMouseDown = False

    End Sub

#End Region

End Class

4TreeViewTextStyle类源代码,自定义列style,实现一般文本类型的显示:

#Region "自定义列style,实现一般文本类型的显示"

Public Class TreeViewTextStyle : Inherits TreeViewColStyle

#Region "类变量区"

    Private xMagin As Integer = 2

    Private yMagin As Integer = 2

    '字体颜色

    Private m_TextColor As Color = SystemColors.ControlDarkDark

#End Region

#Region "对外属性区"

    Public Property TextColor() As Color

        Get

            Return Me.m_TextColor

        End Get

        Set(ByVal Value As Color)

            Me.m_TextColor = Value

        End Set

    End Property

#End Region

#Region "类对外方法区"

    '提供上层调用,得知上层提供的bounds下的实际paintbounds

    Public Overrides Function GetCellBounds(ByVal Bounds As Rectangle) As Rectangle

        Return Bounds

    End Function

    '提供给上层调用的paint方法

    Public Overrides Sub Paint(ByRef g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal Source As String, ByVal Font As Font, ByVal IsSelected As Boolean)

        '根据bounds画出文本

        g.DrawString(Source, Font, New SolidBrush(Me.m_TextColor), bounds.X + xMagin, bounds.Y + yMagin)

    End Sub

#End Region

End Class

#End Region

5TreeViewLinkTextStyle类源代码,自定义列style,实现一般链接文本类型的显示:

#Region "自定义列style,实现一般链接文本类型的显示"

Public Class TreeViewLinkTextStyle : Inherits TreeViewColStyle

#Region "类变量区"

    '判断是否鼠标按下,以显示鼠标按下的图像

    'Private IsMouseDown As Boolean = False

    Private xMagin As Integer = 2

    Private yMagin As Integer = 2

    '字体颜色

    Private m_TextColor As Color = SystemColors.ControlDarkDark

#End Region

#Region "对外属性区"

    Public Property TextColor() As Color

        Get

            Return Me.m_TextColor

        End Get

        Set(ByVal Value As Color)

            Me.m_TextColor = Value

        End Set

    End Property

#End Region

#Region "类对外方法区"

    '提供上层调用,得知上层提供的bounds下的实际paintbounds

    Public Overrides Function GetCellBounds(ByVal Bounds As Rectangle) As Rectangle

        Return Bounds

    End Function

    '提供给上层调用的paint方法

    Public Overrides Sub Paint(ByRef g As System.Drawing.Graphics, ByVal bounds As System.Drawing.Rectangle, ByVal Source As String, ByVal Font As Font, ByVal IsSelected As Boolean)

        '根据bounds画出文本

        Dim f As New Font(Font, FontStyle.Underline)

        g.DrawString(Source, f, New SolidBrush(Me.m_TextColor), bounds.X + xMagin, bounds.Y + yMagin)

    End Sub

#End Region

    '让鼠标mousemove时形状为小手

    Public Sub New()

        Cursor = Cursors.Hand

    End Sub

End Class

#End Region

如果你不满足上面的button列,链接列的显示,还可以自己重写TreeViewColStyle,生成自己想要的列

事件留了一个接口

Public Event TreeViewClick(ByVal ClickNode As TreeNode, ByVal CurrentCol As Integer)

上面的button的点击事件可以通过TreeViewClick获得,其实每一列都有此事件,就看使用时判断CurrentCol 得知是哪一列发出的就行了,谢谢阅读,希望有什么意见能和我联系,ganenping@mainone.com.cnQQ: 44460100

 

以下是测试程序源代码:

Public Class Form1

    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()

        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。

        InitializeComponent()

        ' InitializeComponent() 调用之后添加任何初始化

        buttonstyle = New CustomTreeview.TreeViewButtonStyle

        TextStyle = New CustomTreeview.TreeViewTextStyle

        LinkTextStyle = New CustomTreeview.TreeViewLinkTextStyle

        LinkTextStyle.TextColor = Color.Blue

        'TreeView1.BackgroundImage = Image.FromFile(Application.StartupPath & "\begin.gif")

        TreeView1.AddTreeViewColumnStyles(TextStyle)

        TreeView1.AddTreeViewColumnStyles(buttonstyle)

        TreeView1.AddTreeViewColumnStyles(LinkTextStyle)

    End Sub

    '窗体重写 dispose 以清理组件列表。

    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

    'Windows 窗体设计器所必需的

    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的

    '可以使用 Windows 窗体设计器修改此过程。

    '不要使用代码编辑器修改它。

    Friend WithEvents OwnTreeView1 As CustomTreeview.OwnTreeView

    Friend WithEvents TreeView1 As CustomTreeview.OwnTreeView

    Friend WithEvents Button1 As System.Windows.Forms.Button

    Private buttonstyle As CustomTreeview.TreeViewButtonStyle

    Private TextStyle As CustomTreeview.TreeViewTextStyle

    Private LinkTextStyle As CustomTreeview.TreeViewLinkTextStyle

    Friend WithEvents TreeView2 As System.Windows.Forms.TreeView

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        Me.TreeView1 = New CustomTreeview.OwnTreeView

        Me.Button1 = New System.Windows.Forms.Button

        Me.TreeView2 = New System.Windows.Forms.TreeView

        Me.SuspendLayout()

        '

        'TreeView1

        '

        Me.TreeView1.Cursor = System.Windows.Forms.Cursors.Default

        Me.TreeView1.ImageIndex = -1

        Me.TreeView1.Indent = 15

        Me.TreeView1.LineColor = System.Drawing.Color.DarkGreen

        Me.TreeView1.Location = New System.Drawing.Point(176, 24)

        Me.TreeView1.Name = "TreeView1"

        Me.TreeView1.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点0", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点0,fdsa", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点6,ffff", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点7,ffff", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点0,fdsf", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点1,fdsa", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点2,fgas", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点3,hhhh", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点4,dfgg")})})})})}), New System.Windows.Forms.TreeNode("节点9,ffff")}), New System.Windows.Forms.TreeNode("节点10,ffff")})}), New System.Windows.Forms.TreeNode("节点1,wddd,www.sohu.com"), New System.Windows.Forms.TreeNode("节点2,hgds"), New System.Windows.Forms.TreeNode("节点3,hgfs"), New System.Windows.Forms.TreeNode("节点4,jhgf,www.sina.com", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点5,hgfd")}), New System.Windows.Forms.TreeNode("节点8,ffff,中国企业网"), New System.Windows.Forms.TreeNode("节点0"), New System.Windows.Forms.TreeNode("节点1"), New System.Windows.Forms.TreeNode("节点2"), New System.Windows.Forms.TreeNode("节点3"), New System.Windows.Forms.TreeNode("节点4"), New System.Windows.Forms.TreeNode("节点5"), New System.Windows.Forms.TreeNode("节点6")})

        Me.TreeView1.PlusMinusBorderColor = System.Drawing.Color.DarkGreen

        Me.TreeView1.PlusMinusColor = System.Drawing.Color.DarkOrange

        Me.TreeView1.SelectedImageIndex = -1

        Me.TreeView1.Seperator = ","

        Me.TreeView1.Size = New System.Drawing.Size(272, 208)

        Me.TreeView1.TabIndex = 1

        '

        'Button1

        '

        Me.Button1.Location = New System.Drawing.Point(40, 232)

        Me.Button1.Name = "Button1"

        Me.Button1.Size = New System.Drawing.Size(56, 24)

        Me.Button1.TabIndex = 2

        Me.Button1.Text = "Button1"

        '

        'TreeView2

        '

        Me.TreeView2.ImageIndex = -1

        Me.TreeView2.Location = New System.Drawing.Point(56, 56)

        Me.TreeView2.Name = "TreeView2"

        Me.TreeView2.Nodes.AddRange(New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点0"), New System.Windows.Forms.TreeNode("节点1"), New System.Windows.Forms.TreeNode("节点2", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点10", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点11")})}), New System.Windows.Forms.TreeNode("节点3", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点8", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点9")})}), New System.Windows.Forms.TreeNode("节点4"), New System.Windows.Forms.TreeNode("节点5"), New System.Windows.Forms.TreeNode("节点6", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点12", New System.Windows.Forms.TreeNode() {New System.Windows.Forms.TreeNode("节点13")})}), New System.Windows.Forms.TreeNode("节点7")})

        Me.TreeView2.SelectedImageIndex = -1

        Me.TreeView2.Size = New System.Drawing.Size(96, 128)

        Me.TreeView2.TabIndex = 3

        '

        'Form1

        '

        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

        Me.ClientSize = New System.Drawing.Size(632, 273)

        Me.Controls.Add(Me.TreeView2)

        Me.Controls.Add(Me.Button1)

        Me.Controls.Add(Me.TreeView1)

        Me.Name = "Form1"

        Me.Text = "Form1"

        Me.ResumeLayout

摘自:http://dev.21tx.com/2004/02/09/10342.html

posted on 2013-01-11 16:10  孤独的猫  阅读(525)  评论(0)    收藏  举报