473,382 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Creating Control Array

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
Nov 21 '05 #1
10 1576
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,
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


Nov 21 '05 #2
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
///
Nov 21 '05 #3
"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 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/>
Nov 21 '05 #4
I've come across this problem before, and the only way I could get an ID like
in VB6 is to use the tag property, and then use sender.Tag in the event
handler. But I'm watching to see if anybody suggests a better method.
"Tor Inge Rislaa" wrote:
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

Nov 21 '05 #5
Bonj,

See in my sample in this thread this part

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

With that you can create a control array exactly as you want and from all
parents whatever that is there parent.

Cor
Nov 21 '05 #6
"Cor Ligthert" <no************@planet.nl> schrieb:
See in my sample in this thread this part

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

With that you can create a control array exactly as you want
and from all parents whatever that is there parent.


But you don't associate an ID with the items in the array, except the unique
reference passed to the handler in 'sender'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #7
Herfried,
But you don't associate an ID with the items in the array, except the
unique
reference passed to the handler in 'sender'.


I get the reference as well when I add an handler, where would I need it
more?
For the rest I can reference it direct in my opinion. So maybe you can clear
for me where I do not understand you?

I do not see what I cannot get

directcast(myarray(0), control).text etc

Give me an example?

Cor

Nov 21 '05 #8
"Cor Ligthert" <no************@planet.nl> schrieb:
I do not see what I cannot get

directcast(myarray(0), control).text etc

Give me an example?

Well, assume that you want to associate an item ID with a button, then using
the 'Tag' property is IMO a good idea:

\\\
.... = DirectCast(sender, Control).Tag
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #9
>
Well, assume that you want to associate an item ID with a button, then
using
the 'Tag' property is IMO a good idea:

\\\
... = DirectCast(sender, Control).Tag
///

You can do everything with it (read beneath this also)
\\\
Dim btnArea As Button() = New Button() {Button1}
btnArea(0).Tag = "Hello Herfried"
MessageBox.Show(btnArea(0).Tag.ToString)
///
I think you are mixing this up with the toolbar, for that I have saved your
sample as snippet .

Cor
Nov 21 '05 #10
"Cor Ligthert" <no************@planet.nl> schrieb:
I think you are mixing this up with the toolbar


I think you missed that my post should provide an extension, not a
replacement to your post.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Venkatesh | last post by:
Hi Everybody, This is the first timw I am entering into this Group. I am developing a VB Project with an MDI form. I want to display IE Favorites into my application. For this I need to...
3
by: Rahul Joshi | last post by:
Hi, I want to create a static array whose size is also a const member of the class. Something like: // A.h class A { private: static int size = 0; static int array;
3
by: Mani | last post by:
Hi, can anyone help me on how to create a control array in C++ builder like we create in VB. I have another question regarding controls. I want to clear a group of text boxes in the form on a...
3
by: Mark Broadbent | last post by:
In VB6 (using visual studio) it was possible to create a control array at design time by simply adding the control (e.g. textbox) and renaming it to what would become the first element e.g. ...
2
by: Homer | last post by:
Hi, Have a quick question: Lets say I have a Hashtable of values hence 56 37.890 1 12.768 5 9.764 etc.... Is there a way for me to draw a chart in C# of this. FYI its actually lottery...
2
by: vivek | last post by:
Hello Every body, I am tring to make an array of server controls with array indes can change dynamically. But I was not able to get the refrence of the control outside the scope in which they...
10
by: Adrian | last post by:
Hi In VB6 if you copied and then past a control it asked you if you want to create an array dotnet doesn't! I want to create an array of Labels at design time not runtime can this be done in VB...
2
by: Dino | last post by:
I need to create a public multi-dim array that can hold a mixture of string and int values. I will need to search this array for a value and return a value from a subscript. This array will...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.