成都创新互联网站制作重庆分公司

vb.net同类型控件 vb中控件有哪些

vb.net有没有类似vb6.0控件数组的功能

可以实现

创新互联主营潮州网站建设的网络公司,主营网站建设方案,重庆App定制开发,潮州h5成都小程序开发搭建,潮州网站营销推广欢迎潮州等地区企业咨询

首先创建一个Button类型控件数组:

1、创建“Windows应用程序”类型的工程,添加名为ButtonArray的类,并使该类继承 System.Collection.CollectionBase 类。System.Collections.CollectionBase类是.NET框架类库中为集合操作提供抽象的基类,通过对它的继承可以为我们的ButtonArray类具备集合增加、删除、索引的功能。

2、为ButtonArray类添加ParentForm属性,即控件组所在窗体,创建初始化函数(构造函数);

3、为控件数组类增加AddItem方法,该方法在控件数组类中添加成员;

4、为控件数组类增加RemoveItem方法,该方法在控件数组中删除一个成员。

示例代码:

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的List 属性从CollectionBase 继承

End Get

End Property

Public Sub AddItem()

Dim btnItem As New System.Windows.Forms.Button

Me.List.Add(btnItem)

ParentForm.Controls.Add(btnItem) '向窗体中增加控件

btnItem.Tag = Me.Count 'Count属性从CollectionBase 继承

btnItem.Top = Me.Count * 30

btnItem.Left = 200

btnItem.Text = "Button" Me.Count.ToString

AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序

End Sub

Public Sub AddItem(ByVal btnItem As System.Windows.Forms.Button)

Me.List.Add(btnItem)

AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序

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)

'在这里编写控件数组对点击事件的响应

'例如:

MsgBox("点击:" sender.GetType().ToString CType(CType(sender, Button).Tag, String))

End Sub

End Class

使用创建的控件数组

在Form1中放置两个按钮Button1、Button2,分别测试控件数组的增添、删除。

双击Form添加代码:

Public Class Form1

Inherits System.Windows.Forms.Form

……Windows窗体设计器生成的代码……

Dim Buttons As New ButtonArray(Me)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Buttons.AddItem()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Buttons.RemoveItem()

End Sub

End Class

其他的控件数组也可以用类似的方式来实现

例如 Label控件数组

LabelArray.vb代码如下:

Public Class LabelArray

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.Label

Get

Return Me.List.Item(index) ' ButtonArray的List 属性从CollectionBase 继承

End Get

End Property

Public Sub AddItem(ByVal btnItem As System.Windows.Forms.Label)

Me.List.Add(btnItem)

AddHandler btnItem.Click, AddressOf btnItem_Click '绑定事件处理程序

End Sub

Public Sub btnItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)

'在这里编写控件数组对点击事件的响应

'例如:

MsgBox("点击:" sender.GetType().ToString CType(CType(sender, Label).Tag, String))

End Sub

End Class

使用创建的Label控件

在Form1中放置两个按钮Label1、Label2

双击Form添加代码:

Public Class Form1

Inherits System.Windows.Forms.Form

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

Public Sub New()

MyBase.New()

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

InitializeComponent()

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

'用来绑定label

BindArray()

End Sub

……Windows窗体设计器生成的其他代码……

#End Region

Dim Labels As New LabelArray(Me)

Public Sub BindArray()

Me.Label1.Tag = "1111"

Me.Label2.Tag = "222"

Labels.AddItem(Me.Label1)

Labels.AddItem(Me.Label2)

End Sub

End Class

然后可以测试点击两个label可以显示相应的Tag的信息。

vb中的ADODB.Recordset 控件在vb.net里相同功能的是什么控件

vb.NET中也有ADODB.Recordset,但我们一般用SqlDataReader来实现相同的效果。

Adodb.RecordSet在VB.Net中相对应的是DataTable。这个东西比RecordSet灵活而且支持丰富的过滤及计算方法。

vb.net怎样获取同类控件名称

Private ctrName As String '控件名称

Private isClick As Boolean '鼠标点击状态

'注:如果已知点击目标控件的父控件,ctrParent变量可以不要。

Private WithEvents ctrParent As Control '父控件

Private Sub ControlAMouseDown(sender As Object, e As MouseEventArgs) _

Handles Button1.MouseDown

isClick = (e.Button = MouseButtons.Left _

Or e.Button = MouseButtons.Right) '左键或右键按下

If isClick Then

Dim ctr As Control = CType(sender, Control) '转换Object为控件类型

ctrName = ctr.Name '获取控件名称

ctrParent = ctr.Parent '获取控件的父控件

End If

End Sub

'增加这个父控件事件,是为了正确判别鼠标弹起时是否已进入指定目标

Private Sub ParentMouseMove(sender As Object, e As EventArgs) _

Handles ctrParent.MouseMove '如果已取消ctrParent变量,改为相应的父控件

If isClick Then isClick = False '点击状态关闭

End Sub

Private Sub ControlBMouseUp(sender As Object, e As EventArgs) _

Handles Button2.MouseEnter

If isClick Then '如果点击状态为打开

Dim ctr As Control = CType(sender, Control) '转换Object为控件类型

MsgBox(ctrName  " | "  ctr.Name) '弹出消息显示结果

End If

End Sub

VB.NET设计的窗体程序,有什么控件可以实现类似这种下载列表一样的?

如果是.NET平台的,你可以使用ComponentOne Enterprise 全功能.NET控件集中的布局控件实现。也可以试试ComponentOne的LinearGauge 控件,这是一个线性仪表器,显示为一个值和象征参考值的可选范围。线性仪表盘(LinearGauge)控件提供了一个 ShowText 属性,用来决定哪些值以文本显示。

》》传送门:网页链接


网页标题:vb.net同类型控件 vb中控件有哪些
分享地址:http://cxhlcq.com/article/doohpcg.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部