分享
 
 
 

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

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

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

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

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

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

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

代码如下

1。OwnTreeView类源代码:

#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

'根据所在节点,取得style的bounds

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

2。TreeViewColStyle类源代码:

#Region "自定义TreeView列Style基类,所有的列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

3。TreeViewButtonStyle类源代码,实现双色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下的实际paint的bounds

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

4。TreeViewTextStyle类源代码,自定义列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下的实际paint的bounds

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

5。TreeViewLinkTextStyle类源代码,自定义列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下的实际paint的bounds

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.cn qq: 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(False)

End Sub

#End Region

End Class

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有