?
Solved

Putting controls on form

Posted on 2000-04-19
10
Medium Priority
?
164 Views
Last Modified: 2010-05-02
I need to put some controls on form in Visual Basic at run time. How do I do it?
0
Comment
Question by:sshayevich
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:jjmartin
ID: 2731513
Add the first control, and give it an index of zero. (i.e. cmdTest(0)

Then, at runtime you can use the load method to load a new control:

Load cmdTest(1)

Then you have to postion it (it is loaded in exactly the same postion as the control with an index of zero) and set the visible property to true in order to see it.
0
 
LVL 9

Accepted Solution

by:
Ruchi earned 400 total points
ID: 2731515
You need to delcare a variable to hold the reference to the control. Use the add method to create the instance of the control. Set the properties of the control to position it on the form and make it visible to you.

Try something like this...

Private Sub Command1_Click()
Dim otxtnew As TextBox

Set otxtnew = Controls.Add("VB.Textbox", "otxtNew")
With otxtnew
..Visible = True
..Text = "New Control"
..Width = Me.TextWidth(.Text) + 200
..Height = Me.TextHeight(.Text) + 50
..Top = 100
..Left = 300
End With
End Sub
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731516
At design time give the control an index of 0 so as to create a control array. Then when you want to load a new instance of it, do it like this:

Textbox for example

Load Text(1)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 28

Expert Comment

by:AzraSound
ID: 2731520
geez i type slow
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2731576
0
 

Expert Comment

by:gfaucher
ID: 2731605
place all the controls you need on your form when building it an put the visible property at false then at run time change the visible at true for the control you need to use
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731619
gfaucher...the question was how to add controls at run time.
0
 

Author Comment

by:sshayevich
ID: 2731651
When I try to add a new control to controls collection of the form, I don't get a list of properties and methods where I can pull the Add method from. Any idea why?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2731670
if youre talking about the convenient popup menus that appear when you normally type in comments like text1.text (when you type the "."), that won't appear when referencing the control collection of the form. However it doesnt mean its not working.  It should still run fine.
0
 

Author Comment

by:sshayevich
ID: 2731732
Thank you!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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