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 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
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" <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/>
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
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
"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/>
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
"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/>
> 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
"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/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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;
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |