Adding Controls at run time 
Author Message
 Adding Controls at run time

I am creating a form where I would like the number of text boxes that
appears depends on a number the user chooses.

How can I create the text boxes as needed as opposed to putting all of them
on the form and making the unneeded ones invisible.

I checked MSDN library and could not find anything.
TIA

Gary



Fri, 28 Feb 2003 22:03:02 GMT  
 Adding Controls at run time
Gary,

Put a textbox on your form and set it's index property to 0 and it's visible
property to false.
Put a second textbox on the form so the user can enter the number of
textboxes desired.
Next put a command button to confirm and create the number of textboxes
desired.

in the command buttons click event put the following code,

Dim numTextboxes, counter
numTextboxes = text2.text

for counter = 1 to numTextboxes
    load text1(counter)
    text1(counter).left = 100
    text1(counter).top = counter * 300   ' 300 as long as the scalemode
property of the form is Twips
    text1(counter).visible = true
next counter

Hope this helps, if your still unclear about this just look up "Control
Arrays" in VB help.

Regards,
Jonathan Roach - CEO Stormdev Software Development



Quote:
> I am creating a form where I would like the number of text boxes that
> appears depends on a number the user chooses.

> How can I create the text boxes as needed as opposed to putting all of
them
> on the form and making the unneeded ones invisible.

> I checked MSDN library and could not find anything.
> TIA

> Gary



Fri, 28 Feb 2003 23:05:10 GMT  
 Adding Controls at run time

You may do it following those steps:

1. In design time, drop a textbox control to the form, say Text1, set Index = 0
2. set this control Visible = false.
3. in running time, add the code

            Private Sub Form_Load()
      Load Text1(1)
      Text1(1).Top = 100
      Text1(1).Left = 100
      Text1(1).Visible = True

      Load Text1(2)
      Text1(2).Top = 500
      Text1(2).Left = 100
      Text1(2).Visible = True

  End Sub

Quote:

> I am creating a form where I would like the number of text boxes that
> appears depends on a number the user chooses.

> How can I create the text boxes as needed as opposed to putting all of them
> on the form and making the unneeded ones invisible.

> I checked MSDN library and could not find anything.
> TIA

> Gary



Fri, 28 Feb 2003 23:40:06 GMT  
 Adding Controls at run time
Look into using Load and Unload.  They use controls arrays.  Easiest way is
to open a form in design mode.  Put one text box on the form.  Set all the
properties that you want, give it a good name, then copy and paste it saying
Yes to create a control array.  Then erase that one you just pasted.  Now
you are back to one, but it is Index 0 in the control array of that Text
box.  Then read up on how to use Load and Unload to create copies of it at
runtime.

--
-Clint LaFever
http://lafever.iscool.net
Home of the Visual Basic Code Depot Add-In

VOTE for my wife in the Lycos Model Search 2000
http://clubs.lycos.com/live/Directory/PhotoAlbum.asp?CG=llfae5c88va13...
mohh08&AID=61792&query=fitdiva


Quote:
> I am creating a form where I would like the number of text boxes that
> appears depends on a number the user chooses.

> How can I create the text boxes as needed as opposed to putting all of
them
> on the form and making the unneeded ones invisible.

> I checked MSDN library and could not find anything.
> TIA

> Gary



Sat, 01 Mar 2003 02:38:39 GMT  
 Adding Controls at run time
BTW:  If you just use the help file and type in Adding controls at runtime,
you would have found the same info.

--
-Clint LaFever
http://lafever.iscool.net
Home of the Visual Basic Code Depot Add-In

VOTE for my wife in the Lycos Model Search 2000
http://clubs.lycos.com/live/Directory/PhotoAlbum.asp?CG=llfae5c88va13...
mohh08&AID=61792&query=fitdiva


Quote:
> I am creating a form where I would like the number of text boxes that
> appears depends on a number the user chooses.

> How can I create the text boxes as needed as opposed to putting all of
them
> on the form and making the unneeded ones invisible.

> I checked MSDN library and could not find anything.
> TIA

> Gary



Sat, 01 Mar 2003 02:39:12 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Adding controls at run-time

2. Add Controls at Run Time

3. Add control at run time?

4. Adding Control at Run time

5. Adding Control at Run time

6. Add Controls at run time in VB

7. How to add controls at run time?

8. Adding Controls At Run Time

9. Adding Controls at Run Time

10. Help on adding controls in run time

11. how to dynamically add control at run time

12. HELP!!! Adding controls at run-time

 

 
Powered by phpBB® Forum Software