How to create a text box in run time ? 
Author Message
 How to create a text box in run time ?

Hi,
I am trying to create a textbox in run time (not drug & drop from the tool
box, but coding it and createing it in run time). Any information about how
to do it ?

Thanks,
Zohar



Mon, 08 Sep 2003 19:52:58 GMT  
 How to create a text box in run time ?
Hi,
I am trying to create a textbox in run time (not drug & drop from the tool
box, but coding it and createing it in run time). Any information about how
to do it ?

Thanks,
Zohar



Mon, 08 Sep 2003 19:52:58 GMT  
 How to create a text box in run time ?
You need to already have one textbox on your form, set up as a control array
with index 0.

You can then use the Load command to create new instances of this control
and position them as required.


Quote:
> Hi,
> I am trying to create a textbox in run time (not drug & drop from the tool
> box, but coding it and createing it in run time). Any information about
how
> to do it ?

> Thanks,
> Zohar



Mon, 08 Sep 2003 21:55:39 GMT  
 How to create a text box in run time ?
You have to have at least one textbox on the form before you can
dynamically create another one.  You can't just create a whole new
textbox, but you can load a new member of a control array.

At design time, when you create the first text box, make sure you set
its Index property to 0.  If the name of this textbox is Text1, then to
get the second box you could use the following code:

dim txtNewBox as TextBox
Load Text1(1)
Set txtNewBox=Text1(1)    'only if you want to refer to it by a
different name

You can then set all the properties in code.

If you wish to load more than one new textbox, use a variable to count
how many you have, and make sure you don't try to Load a box with the
same index twice.  You can also Unload a textbox when you are done with
it.



Mon, 08 Sep 2003 22:04:21 GMT  
 How to create a text box in run time ?
This is essentially no different to using the VB form designer; the form
designer declares the object 'WithEvents', and performs the CreateObject()
call for you (Controls.Add simply calls CreateObject() then adds the control
to the collection).  Doing it manually only takes implementation time, and
is probably slower.

In addition, your solution would allow only one instance of a textbox to be
created dynamically; the previous textbox is lost as soon as you attempt to
create an additional instance using the same method.

Surely, if you know how many textboxes you are going to need at design-time,
why wait until run-time to create them.  Surely not so you can specify
location, size, style, etc. manually?

==============================
Nik Rivers
Software Development Engineer
Gladstone PLC [www.gladstoneplc.com]


Quote:
> To create a TextBox (or any control) at runtime use this:

> 'In the Declarations section of the Form:

> 'After this declaration is in place you can
> 'look in the "objects" dropdown list and see
> 'txtMyTextBox with all of its events in place.
> 'You can even add code in the events.
> Private WithEvents txtMyTextBox As TextBox

> 'In the Form_Load event or wherever you'd like:
> Private Sub Form_Load()

> Dim fScale  As Single

>     'Create the Control (Syntax - Add("ControlType", "ControlName")
>     Set txtMyTextBox = Me.Controls.Add("VB.TextBox", "txtMyTextBox")

>     'Get scale for Twips on this form
>     fScale = Me.ScaleX(1, vbTwips, Me.ScaleMode)

>     'Move it into place, add some text and make it visible
>     With txtMyTextBox
>         .Move 90 * fScale, 90 * fScale, 1500 * fScale, 315 * fScale
>         .Text = .Name
>         .Visible = True
>     End With

> End Sub

> Hope this helps'
> Rocky Clark (Kath-Rock Software)



> > Hi,
> > I am trying to create a textbox in run time (not drug & drop from the
tool
> > box, but coding it and createing it in run time). Any information about
> how
> > to do it ?

> > Thanks,
> > Zohar



Mon, 08 Sep 2003 23:48:33 GMT  
 How to create a text box in run time ?
To create a TextBox (or any control) at runtime use this:

'In the Declarations section of the Form:

'After this declaration is in place you can
'look in the "objects" dropdown list and see
'txtMyTextBox with all of its events in place.
'You can even add code in the events.
Private WithEvents txtMyTextBox As TextBox

'In the Form_Load event or wherever you'd like:
Private Sub Form_Load()

Dim fScale  As Single

    'Create the Control (Syntax - Add("ControlType", "ControlName")
    Set txtMyTextBox = Me.Controls.Add("VB.TextBox", "txtMyTextBox")

    'Get scale for Twips on this form
    fScale = Me.ScaleX(1, vbTwips, Me.ScaleMode)

    'Move it into place, add some text and make it visible
    With txtMyTextBox
        .Move 90 * fScale, 90 * fScale, 1500 * fScale, 315 * fScale
        .Text = .Name
        .Visible = True
    End With

End Sub

Hope this helps'
Rocky Clark (Kath-Rock Software)


Quote:
> Hi,
> I am trying to create a textbox in run time (not drug & drop from the tool
> box, but coding it and createing it in run time). Any information about
how
> to do it ?

> Thanks,
> Zohar



Mon, 08 Sep 2003 23:18:46 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. How to create a text box in run time ?

2. How to create a text box in run time ?

3. Create Text Box or Label at Run Time ?

4. Creating new text boxes at run time

5. Creating new text boxes at run time

6. Create Multiline Text Box at Run Time

7. About creating RTF Boxes at run-time

8. loading text boxes at run-time

9. changing the datasource property of a text box at run time

10. HELP: Adding text boxes during run time

11. Drag Text Box In Run Time

12. New Text Box during Run-time

 

 
Powered by phpBB® Forum Software