Creating new text boxes at run time 
Author Message
 Creating new text boxes at run time

Is it possible to create and display new textbox controls (or other controls for that matter) on a regular VB form at run time?

I had hoped to do something like this:

Private Sub Form_Load()

    Dim txt As TextBox
    Dim i As Integer

    For i = 1 To 10
        Set txt = new TextBox
        txt.name = "field" & CStr(i)

        ...
        Do other stuff here...
        ...

    Next i
End Sub

This doesn't work because although it is possible to dimension a variable as a TextBox, the line "Set txt = New TextBox" is not valid.  'TextBox' doesn't show up in the code completion list.

So is it at all possible to create new textbox controls on my form at run-time?  If so, am I at all close with my example above?  Or is there some other way to do this?

Please advise.

Thanks!

--
Tom Castiglia
Hershey Technologies

www.hersheytech.com
(858) 458-4222 x18



Sat, 25 May 2002 03:00:00 GMT  
 Creating new text boxes at run time

You can use the Load statement if you have a control array seed.

And there's the API CreateWindow if you feel like you have an extra hour or so to write message handler code.

And there's the VB6 way using:
   Dim TheTextBox As TextBox
    Set TheTextBox = Form1.Controls.Add("VB.TextBox", "Text1")

I'd try the "Controls.Add" approach. It seems to work OK.

--
Monte Hansen
Vb Yuk Yuk


  Is it possible to create and display new textbox controls (or other controls for that matter) on a regular VB form at run time?

  I had hoped to do something like this:

  Private Sub Form_Load()

      Dim txt As TextBox
      Dim i As Integer

      For i = 1 To 10
          Set txt = new TextBox
          txt.name = "field" & CStr(i)

          ...
          Do other stuff here...
          ...

      Next i
  End Sub

  This doesn't work because although it is possible to dimension a variable as a TextBox, the line "Set txt = New TextBox" is not valid.  'TextBox' doesn't show up in the code completion list.

  So is it at all possible to create new textbox controls on my form at run-time?  If so, am I at all close with my example above?  Or is there some other way to do this?

  Please advise.

  Thanks!

  --
  Tom Castiglia
  Hershey Technologies

  www.hersheytech.com
  (858) 458-4222 x18



Sat, 25 May 2002 03:00:00 GMT  
 Creating new text boxes at run time
Hi Tom:

Quote:
>Is it possible to create and display new textbox controls (or other

controls for that matter) on a regular VB form at run time?

You can either Load new instances of a control from a control array, i.e.

    Load Text1(MyNewIndex)

Or you can use the Controls.Add method (VB6 -- see VB docs for more
specifics).

HTH,

--
Doug Marquardt (VB MVP)



Sat, 25 May 2002 03:00:00 GMT  
 Creating new text boxes at run time
Create a text box array by adding one to a form and setting its index
property to 0. Then just use:

Private Sub Command1_Click()

    Dim x As Integer

    For x = 0 To 9

        If x > 0 Then Load Text1(x)
        Text1(x).Text = "field" & CStr(x)
        Text1(x).Left = 300
        Text1(x).Top = 360 * x
        Text1(x).Visible = True

      '  ...
      ' Do other stuff here...
      '  ...

    Next x

End Sub

Note that you can not assign a value to the Name property at runtime.

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


Is it possible to create and display new textbox controls (or other controls
for that matter) on a regular VB form at run time?

I had hoped to do something like this:

Private Sub Form_Load()

    Dim txt As TextBox
    Dim i As Integer

    For i = 1 To 10
        Set txt = new TextBox
        txt.name = "field" & CStr(i)

        ...
        Do other stuff here...
        ...

    Next i
End Sub

This doesn't work because although it is possible to dimension a variable as
a TextBox, the line "Set txt = New TextBox" is not valid.  'TextBox' doesn't
show up in the code completion list.

So is it at all possible to create new textbox controls on my form at
run-time?  If so, am I at all close with my example above?  Or is there some
other way to do this?

Please advise.

Thanks!

--
Tom Castiglia
Hershey Technologies

www.hersheytech.com
(858) 458-4222 x18



Sat, 25 May 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Creating new text boxes at run time

2. New Text Box during Run-time

3. make new text-boxes at run-time

4. Create Text Box or Label at Run Time ?

5. Create Multiline Text Box at Run Time

6. Text box text on new page text box

7. Creating new controls at run time

8. Needed to create a new option button at run time

9. Creating new tabs in SSTab at run time

10. Creating new interface controls at run time

11. Creating new components from code in run time.

12. Creating new components from code in run time.

 

 
Powered by phpBB® Forum Software