创建控制数组 [英] Creating Control Array

查看:68
本文介绍了创建控制数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建控制数组


如何创建一个按钮数组,使用基于指数

控件的常用程序。


这个来自VB 6.0的示例如何在VB.NET中?


私有子Command1_Click(索引为整数)


选择案例索引


案例0


MsgBox" Button1点击


案例1


MsgBox" Button2被点击


结束选择


结束Sub


TIRislaa

Creating Control Array

How to create an array of buttons, with common procedures based on the index
of the control.

How would this Example from VB 6.0 be in VB.NET?

Private Sub Command1_Click(Index As Integer)

Select Case Index

Case 0

MsgBox "Button1 is clicked"

Case 1

MsgBox "Button2 is clicked"

End Select

End Sub

TIRislaa

推荐答案

试试这个:


私人按钮(5)按钮


按钮(0)=新按钮()

按钮(1)=新按钮()

按钮(2)=新按钮()

按钮(3)=新按钮()

按钮(4)=新按钮()

Private Sub buttons_Click(sender As System.Object,ByVal e As System.EventArgs)处理按钮(0).Click,buttons(1).Click,button s(2)。点击,按钮(3)。点击,按钮(4)。点击,按钮(5)。点击


结束子

spigi

Hello Tor,
Try this:

Private buttons(5) As Button

button(0) = New Button()
button(1) = New Button()
button(2) = New Button()
button(3) = New Button()
button(4) = New Button()
Private Sub buttons_Click(sender As System.Object, ByVal e As System.EventArgs) Handles buttons(0).Click, buttons(1).Click, buttons(2).Click, buttons(3).Click, buttons(4).Click, buttons(5).Click

End Sub
spigi
Hello Tor,
创建控制数组
如何创建按钮数组,使用基于控件的索引。

VB 6.0中的这个例子如何在VB.NET中?

Private Sub Command1_Click(Index as Integer)

/>选择案例索引

案例0

MsgBox" Button1被点击

案例1

MsgBox" ;单击Button2

结束选择

结束子页面

TIRislaa
Creating Control Array

How to create an array of buttons, with common procedures based on the
index of the control.

How would this Example from VB 6.0 be in VB.NET?

Private Sub Command1_Click(Index As Integer)

Select Case Index

Case 0

MsgBox "Button1 is clicked"

Case 1

MsgBox "Button2 is clicked"

End Select

End Sub

TIRislaa






Tor


有很多方法,比伊戈尔还要多一个


我希望这会有帮助吗?


Cor

\\\

Private Sub Form1_Load(ByVal sender As Object,_

ByVal e As System.EventArgs)处理MyBase.Load

Dim btnArea As Button()= New Button(){Button1,Button2}

每个btn As按钮在btnArea

AddHandler btn.MouseLeave,AddressOf Button_MouseLeave

AddHandler btn.MouseEnter,AddressOf Button_MouseEnter

Next

End Sub

///

\\ \\\\而不是实例使用它

Private Sub Button_MouseLeave(ByVal sender As Object,_

ByVal e As System.EventArgs)

DirectCast(发件人,按钮).BackColor = Color.Black

Me.Label1.Text =""

End Sub

Private Sub Button_MouseEnter(ByVal sender As Object,_

ByVal e As System.EventArgs)

DirectCast(发送者,按钮).BackColor = Color.Red

Me.Label1.Text = DirectCast(发件人,按钮)。名

结束子

///
Tor

There are a lot of methods, another one than Igor

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
AddHandler btn.MouseEnter, AddressOf Button_MouseEnter
Next
End Sub
///
\\\And than use it by instance as
Private Sub Button_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Red
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
///


" Tor Inge Rislaa" <至************* @ rislaa.no> schrieb:
"Tor Inge Rislaa" <to*************@rislaa.no> schrieb:
如何创建一个按钮数组,使用基于控件的
索引的常用过程。
How to create an array of buttons, with common procedures based on the index of the control.




In除了其他评论之外:如果需要,您可以将控件的ID /索引存储在

的标签属性中。


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>



In addition to the other comments: You can store the control''s ID/index in
its ''Tag'' property, if this is needed.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


这篇关于创建控制数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆