Index

G

Guest

Hey guys, i have 5 buttons created on runtime, in vb 6.0, each button had a unique index, how is done in vb.net? bellow is the code

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
Dim i As Integer =
Dim myPic(10) as pictureBo
Dim yAxis As Integer =
For i = 0 To

MyPic(i) = New PictureBo

MyPic(i).Width = 13
MyPic(i).Height = 4

'Mypic(i).Font = New Font("Verdana", 9.75!, FontStyle.Regular

MyPic(i).BackColor = Drawing.Color.Blac
MyPic(i).SizeMode = PictureBoxSizeMode.StretchImag
MyPic(i).Location = New System.Drawing.Point(Left, Top
MyPic(i).Name = "Pic" &
'Mypic(i).Text = rst("ProductName").Valu
MyPic(i).Location = New Point(660, yAxis
MyPic(i).Cursor = Cursors.Han
MyPic(i).BringToFront(
Me.Controls.Add(MyPic(i)
MyPic(i).Image = ImageList1.Images.Item(i

AddHandler MyPic(i).Click, AddressOf mypic_clic
yAxis = yAxis + 5 + MyPic(i).Heigh
Nex
End Su

NEED THE CODE PLEAS

THANX IN ADVANCE
 
P

Patrick Steele [MVP]

Hey guys, i have 5 buttons created on runtime, in vb 6.0, each button
had a unique index, how is done in vb.net?

1) Create a form-level ArrayList.
2) After creating the button, add it to the ArrayList at the specified
index. Example:

myList.Insert(i, myNewButton)

3) In the click event handler, the "sender" object will be the button
that was pushed. Use the "IndexOf" method to find out which button was
pushed:

Dim index As Integer = myList.IndexOf(sender)
 
P

Patrick Steele [MVP]

Great example one question, could you please give me an example (code) on how to create a form-level ArrayList ?
thanx

Just define it outside of all of your methods:

Public Class MyForm
Inherits Form

Private myList As ArrayList = new ArrayList()

...
 
C

Cor

Hi Will,

I do not understand this, this is almost the sample I gave you and the code
is VB.net code how did you do this in VB6?

Cor
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
 
C

Cor

Hi Herfried,

This is a message about a VB.net sample I gave can this be done in VB6?

Cor
 
C

Cor

Hi Patrick,

This is a message about a VB.net sample I gave, can this be done in VB6?

In my sample is no need for an Arraylist I use that almost always, except
when the array is fixed as is in this sample.

Cor
 
C

Cor

Hi Patrick,

This is the correct answer by the way, accoording to my sample, although it
is an array
Just define it outside of all of your methods:

But I did wanted to keep the sample nice and putted it inside the procedure.
Using directcast with the sender in the event, that I also supported (it is
disapeared now), it is not really needed, but when you do more with it, it
can be the answer.

And when the array really becomes dynamic using an arraylist is of course
better.

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

* "Cor said:
This is a message about a VB.net sample I gave can this be done in VB6?

What? Sorry, I don't understand what you want to tell me...

:-(
 
C

Cor

Hi Herfried,

The poster tells that he has created this in VB6 while it is code I
supported to him on 26-1.
(You should have seen it before because I have contributed this so much,
because I find it a real nice example because it is so simple).

And now I am curious if this code can be done in VB6 because you are
answering that.

This is the start of the original thread
Hey guys, i have 5 buttons created on runtime, in vb 6.0, each button had a
unique index, how >is done in vb.net? bellow is the code:

I think that code cannot be done in VB6.

Or am I crazy?

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

* "Cor said:
This is the start of the original thread
unique index, how >is done in vb.net? bellow is the code:

I think that code cannot be done in VB6.

Yes, that can be done in VB6 by using a control array. You can
load/unload buttons to/from the array by using 'Load' and 'Unload' in
VB6.
 
C

Cor

Herfried,

Look at the code he said he made this in VB6.
Yes, that can be done in VB6 by using a control array. You can
load/unload buttons to/from the array by using 'Load' and 'Unload' in
VB6.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Add(MyPic(i))
MyPic(i).Image = ImageList1.Images.Item(i)
AddHandler MyPic(i).Click, AddressOf mypic_click
Next
End Sub

Are you sure of that, than VB6 could more than I thought?

Cor
 
H

Herfried K. Wagner [MVP]

Cor,

* "Cor said:
Look at the code he said he made this in VB6.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Controls.Add(MyPic(i))
MyPic(i).Image = ImageList1.Images.Item(i)
AddHandler MyPic(i).Click, AddressOf mypic_click
Next
End Sub

Are you sure of that, than VB6 could more than I thought?

Yes, something similar was possible with VB6. You could create a
control array and create a common handler for the array. The shared
handler had an index parameter which contained the index of the control
in the control array firing the event.
 
C

Cor

The OP stated that he has written this code with VB6 that is my question.
I believe that something simular was posible exactly this code on VB6
(knowing me you know of course that I tried it already before I wrote this,
but did I see something wrong?)
 
H

Herfried K. Wagner [MVP]

* "Cor said:
The OP stated that he has written this code with VB6 that is my question.

Sorry, I misread. The code the OP posted won't run on VB6.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top