自定义控件之二(左侧OUTLOOK控件)
工作快一年了,发现自己依然很菜。离自己的理想越差越远。也许因为自己是专科生吧。自己写个控件发现就是胡编,没有一点所谓节省资源啊,方便易用性,完全是自己胡扯。若您有兴趣谢谢指导。
代码
1 Imports BizWiseControl.gButton
2 Public Class LeftMenu
3 Public Event leftmenuevent(ByVal ino As Integer)
4 Private _twoMenu As DataTable
5 Dim arry As New ArrayList
6 Public Property twoMenu() As DataTable
7 Get
8 Return _twoMenu
9 End Get
10 Set(ByVal value As DataTable)
11 _twoMenu = value
12 arry.Add(_twoMenu)
13 SetTwoMenu(1)
14 End Set
15 End Property
16 Private _oneMenu As DataTable
17 Public Property oneMenu() As DataTable
18 Get
19 Return _oneMenu
20 End Get
21 Set(ByVal value As DataTable)
22 _oneMenu = value
23 SetOneMenu()
24 End Set
25 End Property
26 Private _myControl As Control()
27 Public Property myControl() As Control()
28 Get
29 Return _myControl
30 End Get
31 Set(ByVal value As Control())
32 _myControl = value
33 End Set
34 End Property
35 Private _preClick As Integer
36 Public Property preClick() As Integer
37 Get
38 Return _preClick
39 End Get
40 Set(ByVal value As Integer)
41 _preClick = value
42 End Set
43 End Property
44 Private Sub SetOneMenu()
45 Dim inti As Integer
46 D_GtwoMenu.Dock = DockStyle.Fill
47 Try
48 If _oneMenu.Rows.Count < 1 Then Exit Sub
49 For inti = 1 To _oneMenu.Rows.Count - 1
50 Dim gb As New gButton
51 gb.modeName = _oneMenu.Rows(inti - 1).Item(2)
52 gb.Name = "Menu" & inti
53 gb.TabIndex = inti
54 AddHandler gb.myevent, AddressOf DoMenu
55 Me.Controls.Add(gb)
56 If gb.Name = "Menu1" Then
57 gb.Dock = DockStyle.Top
58 Else
59 gb.Dock = DockStyle.Bottom
60 gb.SendToBack()
61 End If
62 Next
63 Dim subsctrl(Me.Controls.Count) As Control
64 Me.Controls.CopyTo(subsctrl, 0)
65 myControl = subsctrl
66 Catch ex As Exception
67
68
69 End Try
70 End Sub
71 Private Sub SetTwoMenu(ByVal ino As Integer)
72 Dim inti As Integer
73 Try
74 D_GtwoMenu.RowCount = _twoMenu.Rows.Count
75 For inti = 0 To _twoMenu.Rows.Count - 1
76 D_GtwoMenu.Rows(inti).Cells(0).Value = arry(ino).Rows(inti).Item(2)
77 Next
78 Catch ex As Exception
79
80 End Try
81
82 End Sub
83 Private Sub DoMenu(ByVal sender As System.Object, ByVal e As System.EventArgs)
84 RaiseEvent leftmenuevent(CInt(Mid(sender, 5)))
85 Dim i As Integer
86
87 If Mid(sender, 1, 4) <> "Menu" Then Exit Sub
88
89 If _preClick < CInt(Mid(sender, 5)) Then
90 For i = CInt(Mid(sender, 5)) To 1 Step -1
91 If TypeName(_myControl(i)) <> "gButton" Then
92 D_GtwoMenu.BringToFront()
93 D_GtwoMenu.Dock = DockStyle.Fill
94 Else
95 _myControl(i).Dock = DockStyle.Top
96 _myControl(i).SendToBack()
97 End If
98 Next
99 Else
100 For i = CInt(Mid(sender, 5)) + 1 To Me.Controls.Count
101 If TypeName(_myControl(i)) <> "gButton" Then
102 D_GtwoMenu.BringToFront()
103 D_GtwoMenu.Dock = DockStyle.Fill
104 Else
105 _myControl(i).Dock = DockStyle.Bottom
106 _myControl(i).SendToBack()
107 End If
108 Next
109 End If
110 AddHandler Me.leftmenuevent, AddressOf SetTwoMenu
111 _preClick = CInt(Mid(sender, 5))
112
113 End Sub
114
115 Private Sub D_GtwoMenu_CellMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles D_GtwoMenu.CellMouseMove
116 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue
117 End Sub
118
119 Private Sub D_GtwoMenu_CellMouseLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles D_GtwoMenu.CellMouseLeave
120 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
121 End Sub
122
123 Private Sub D_GtwoMenu_CellMouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles D_GtwoMenu.CellMouseEnter
124 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
125 End Sub
126
127 Public Sub New()
128
129 ' 此调用是 Windows 窗体设计器所必需的。
130 InitializeComponent()
131 Dim cursor As System.Windows.Forms.Cursor = New System.Windows.Forms.Cursor(Me.GetType(), "harrow.cur")
132 D_GtwoMenu.Cursor = cursor
133 ' 在 InitializeComponent() 调用之后添加任何初始化。
134
135 End Sub
136 End Class
137
2 Public Class LeftMenu
3 Public Event leftmenuevent(ByVal ino As Integer)
4 Private _twoMenu As DataTable
5 Dim arry As New ArrayList
6 Public Property twoMenu() As DataTable
7 Get
8 Return _twoMenu
9 End Get
10 Set(ByVal value As DataTable)
11 _twoMenu = value
12 arry.Add(_twoMenu)
13 SetTwoMenu(1)
14 End Set
15 End Property
16 Private _oneMenu As DataTable
17 Public Property oneMenu() As DataTable
18 Get
19 Return _oneMenu
20 End Get
21 Set(ByVal value As DataTable)
22 _oneMenu = value
23 SetOneMenu()
24 End Set
25 End Property
26 Private _myControl As Control()
27 Public Property myControl() As Control()
28 Get
29 Return _myControl
30 End Get
31 Set(ByVal value As Control())
32 _myControl = value
33 End Set
34 End Property
35 Private _preClick As Integer
36 Public Property preClick() As Integer
37 Get
38 Return _preClick
39 End Get
40 Set(ByVal value As Integer)
41 _preClick = value
42 End Set
43 End Property
44 Private Sub SetOneMenu()
45 Dim inti As Integer
46 D_GtwoMenu.Dock = DockStyle.Fill
47 Try
48 If _oneMenu.Rows.Count < 1 Then Exit Sub
49 For inti = 1 To _oneMenu.Rows.Count - 1
50 Dim gb As New gButton
51 gb.modeName = _oneMenu.Rows(inti - 1).Item(2)
52 gb.Name = "Menu" & inti
53 gb.TabIndex = inti
54 AddHandler gb.myevent, AddressOf DoMenu
55 Me.Controls.Add(gb)
56 If gb.Name = "Menu1" Then
57 gb.Dock = DockStyle.Top
58 Else
59 gb.Dock = DockStyle.Bottom
60 gb.SendToBack()
61 End If
62 Next
63 Dim subsctrl(Me.Controls.Count) As Control
64 Me.Controls.CopyTo(subsctrl, 0)
65 myControl = subsctrl
66 Catch ex As Exception
67
68
69 End Try
70 End Sub
71 Private Sub SetTwoMenu(ByVal ino As Integer)
72 Dim inti As Integer
73 Try
74 D_GtwoMenu.RowCount = _twoMenu.Rows.Count
75 For inti = 0 To _twoMenu.Rows.Count - 1
76 D_GtwoMenu.Rows(inti).Cells(0).Value = arry(ino).Rows(inti).Item(2)
77 Next
78 Catch ex As Exception
79
80 End Try
81
82 End Sub
83 Private Sub DoMenu(ByVal sender As System.Object, ByVal e As System.EventArgs)
84 RaiseEvent leftmenuevent(CInt(Mid(sender, 5)))
85 Dim i As Integer
86
87 If Mid(sender, 1, 4) <> "Menu" Then Exit Sub
88
89 If _preClick < CInt(Mid(sender, 5)) Then
90 For i = CInt(Mid(sender, 5)) To 1 Step -1
91 If TypeName(_myControl(i)) <> "gButton" Then
92 D_GtwoMenu.BringToFront()
93 D_GtwoMenu.Dock = DockStyle.Fill
94 Else
95 _myControl(i).Dock = DockStyle.Top
96 _myControl(i).SendToBack()
97 End If
98 Next
99 Else
100 For i = CInt(Mid(sender, 5)) + 1 To Me.Controls.Count
101 If TypeName(_myControl(i)) <> "gButton" Then
102 D_GtwoMenu.BringToFront()
103 D_GtwoMenu.Dock = DockStyle.Fill
104 Else
105 _myControl(i).Dock = DockStyle.Bottom
106 _myControl(i).SendToBack()
107 End If
108 Next
109 End If
110 AddHandler Me.leftmenuevent, AddressOf SetTwoMenu
111 _preClick = CInt(Mid(sender, 5))
112
113 End Sub
114
115 Private Sub D_GtwoMenu_CellMouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles D_GtwoMenu.CellMouseMove
116 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Blue
117 End Sub
118
119 Private Sub D_GtwoMenu_CellMouseLeave(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles D_GtwoMenu.CellMouseLeave
120 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.White
121 End Sub
122
123 Private Sub D_GtwoMenu_CellMouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles D_GtwoMenu.CellMouseEnter
124 D_GtwoMenu.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
125 End Sub
126
127 Public Sub New()
128
129 ' 此调用是 Windows 窗体设计器所必需的。
130 InitializeComponent()
131 Dim cursor As System.Windows.Forms.Cursor = New System.Windows.Forms.Cursor(Me.GetType(), "harrow.cur")
132 D_GtwoMenu.Cursor = cursor
133 ' 在 InitializeComponent() 调用之后添加任何初始化。
134
135 End Sub
136 End Class
137
效果图:(只实现了效果,页面并没有进行修饰)