Solved

loading controls vb.net

Posted on 2006-07-17
1
169 Views
Last Modified: 2012-05-05
I had a vb6 application I am trying to convert.

I had a form, with a control array with one element.

I load the form, then reproduce the controls as I need them.

In this case, they are either text boxes or select boxes.

So if I wanted, I would display 5 of them across.

        If lastStep = 0 Then
            ctrlInputForm1(lastStep).Left = startLeft
            ctrlInputForm1(lastStep).Top = startTop
        Else
            Load ctrlInputForm1(lastStep)
            ctrlInputForm1(lastStep).Left = currentLeft
            ctrlInputForm1(lastStep).Top = currentTop
        end if

All I had to do was load the control with "Load" and it would work.

How can I do this with vb.net?

I need to be able to load controls named "ctrlInputForm" on the fly,
and refer to them somehow, in this case a control array.
0
Comment
Question by:jackjohnson44
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17125448
The control array in this sense no longer exists in VB.Net...

The simplest solution would be to dynamically create new controls and add them to an ArrayList

    Private myTextBoxes As New ArrayList

    Private Sub Foo()
            Dim tb As New TextBox
            tb.Left = currentLeft
            tb.Top = currentTop
            myTextBoxes.Add(tb)
            Me.Controls.Add(tb)   ' or add it to whatever container you need such as "Panel1.Controls.Add(tb)"
    End Sub

You can check the number of items in the ArrayList using Count (or Length...I can't remember which) to determine how many items are already in the array list.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question