In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how to use VB. NET control array, I believe most people still do not know how, so share this article for everyone's reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
VB. NET is very powerful, can achieve code management, and strengthen the code architecture, for programmers to bring a strong security development environment. Here we first create a Button type VB. NET control array, to explain the relevant knowledge points.
1. Create a project of type "Windows Application", add a class named ButtonArray, and make this class inherit the System.Collection. Base class. System.Collections.CollectionBase class is a base class that provides abstraction for collection operations in the. NET Framework class library. By inheriting it, we can add, delete, and index collections for our ButtonArray class.
2. Add ParentForm attribute to ButtonArray class, that is, the form where the control group is located, and create initialization function (constructor);
3. Add AddItem method for control array class, which adds members to control array class;
Add a RemoveItem method to the control array class, which removes a member from the control array.
Example code for VB. NET control array creation:
Public Class ButtonArray
Inherits System.Collections.
CollectionBase
Private ReadOnly ParentForm
As System.Windows.Forms.Form
Public Sub New(ByVal pForm
As System.Windows.Forms.Form)
ParentForm = pForm
End Sub
Default Public ReadOnly Property Item
(ByVal index As Integer) As System.
Windows.Forms.Button
Get
Return Me.List.Item(index)
' ButtonArray's List property is derived from
CollectionBase inheritance
End Get
End Property
Public Sub AddItem()
Dim btnItem As New System.
Windows.Forms.Button
Me.List.Add(btnItem)
ParentForm.Controls.Add
(btnItem) 'Add a control to a form
btnItem.Tag = Me.Count
'Count property inherited from CollectionBase
btnItem.Top = Me.Count * 30
btnItem.Left = 200
btnItem.Text = "Button"
& Me.Count.ToString
AddHandler btnItem.Click,
AddressOf btnItem_Click
'Binding event handlers
End Sub
Public Sub AddItem(ByVal btnItem
As System.Windows.Forms.Button)
Me.List.Add(btnItem)
AddHandler btnItem.Click,
AddressOf btnItem_Click
'Binding event handlers
End Sub
Public Sub RemoveItem()
If Me.Count > 0 Then
ParentForm.Controls.Remove
(Me(Me.Count - 1))
Me.List.RemoveAt(Me.Count - 1)
End If
End Sub
Public Sub btnItem_Click
(ByVal sender As Object,
ByVal e As System.EventArgs)
'Write control array response to click event here
'For example:
MsgBox("Click: " & sender.GetType().
ToString & CType(CType(sender,
Button).Tag, String))
End Sub
End Class
The above is "VB. NET control array how to use" all the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.