Re: Indexed controls on a form.
- From: Grok
- Date: Tue, 12 Feb 2008 16:29:24 -0500
On Thu, 03 Jan 2008 13:06:41 +0000, "Jan Hyde (VB MVP)"
<StellaDrinker@xxxxxxxxxxxxxxxxxxx> wrote:
"Forrest Lawrenceton" <likeidgiveittoya@xxxxxxxxxxxx>'s wild
thoughts were released on Thu, 3 Jan 2008 04:13:51 -0800
bearing the following fruit:
Hi;
The six hours I just spent digging through more mountains of useless
information than can be found via Google didn't pay off. In VB6 we could
simply copy and paste a control onto a form to create a control array
(automatically indexing the controls with the same name). Anybody know how
to go about that in .NET 2005?
You don't need a control array in dotnet, however if you
upgrade a VB6 project you will see how to do it.
My advice is do it the dotnet way and leave the VB6 way
behind.
J
I think what he's saying is do something like this. Let's assume your
VB6 form has a Button control array indexed 0 to 7.
In VB.NET, drop all 8 Button controls on your form.
Double-click Button1 to bring up the code editor for the Click event.
That brings up this code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
End Sub
Pay attention to the wiring at the end, "Handles Button1.Click".
As you know a VB6 control array is wired all to the same event
procedure. To duplicate that behavior here, we tell this procedure to
handle click events for our other Buttons too. Easy.
So we modify this procedure definition slightly.
First, rename it to maybe ... "MyButtonArray_Click"
Then wire it to all 8 Button controls... voila!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click, Button2.Click,
Button3.Click, Button4.Click, Button5.Click, Button6.Click,
Button7.Click, Button8.Click
MessageBox.Show("My name is '" + CType(sender, Button).Name +
"'")
End Sub
Now of course you'll want to do something with the news that your
event fired, and base the logic on which button. This is where the
VB6 control array index starts to be missed. I don't know what to
tell you there, as I only learned how to do the above after reading
your question and wanting to figure out the answer.
.
- Prev by Date: Re: microsoft RDP client control
- Next by Date: Re: Indexed controls on a form.
- Previous by thread: FlowLayoutPanel again
- Next by thread: Re: Indexed controls on a form.
- Index(es):