Solved

Creating Controls  in run-time

Posted on 1998-09-08
7
139 Views
Last Modified: 2010-04-30
How can I create a control (any control, a textbox, a picture control, any OCX control,etc..) in runtime, from scrach?. I mean, it is possible to create a control via code?
0
Comment
Question by:Guillo
7 Comments
 

Expert Comment

by:janim
ID: 1433672
you cannot create a control from scratch unless you already have at least one control (of the type you want to create) that is loaded on your form with index property set to any value.

if you don't want to see this initial control on you form, just set its visible property to false.  you create controls using the 'load' command then make its visible property to true.
0
 

Author Comment

by:Guillo
ID: 1433673
Thanks, Janim, i've alredy assumed that a base control was necesary but i need more information.
OK, I understand the fact to have a contron of the type i want. Then the question is:
Let's suppose i have a command button for 1 action(in this case hidden, because i want this only as a "base"). How can i create copies of this button for x actions (assume that there is a variable ammount of actions, so i don't know how many buttons they may be)?
And, It's possible to do the same with other controls (Activex OCX, data controls, etc)?
Thanks.
0
 

Author Comment

by:Guillo
ID: 1433674
Please help me, i need an answer as soon as possible.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:KEWL
ID: 1433675
there is a function calles 'LoadControl' in VB5, but you need an objects CLSID to use it. but look it up and try it
0
 

Expert Comment

by:janim
ID: 1433676
can you further explain your question?
by action do you mean the event corresponding to your control?
can you give me a sample algorithm of what you need to do?  

0
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1433677
Here is code to add / delete controls at runtime based on a control. This is a sample. I don't know your project :

Private Sub cmdAdd_Click ()
      If MaxId = 0 Then MaxId = 1      ' Set total option
                                                                  ' buttons.
      If MaxId > 8 Then Exit Sub      ' Only ten buttons
                                                                  ' allowed.
      MaxId = MaxId + 1                  ' Increment button count.
      Load optButton(MaxId)            ' Create new button.
      optButton(0).SetFocus            ' Reset button selection.
      ' Set new button under previous button.
      optButton(MaxId).Top = optButton(MaxId - 1)._
      Top + 400
      optButton(MaxId).Visible = True      ' Display new
                                                                  ' button.
      optButton(MaxId).Caption = "Option" & MaxId + 1
End Sub
      
Private Sub cmdDelete_Click ()
      If MaxId <= 1 Then Exit Sub      ' Keep first two
                                                                  ' buttons.
      Unload optButton(MaxId)            ' Delete last button.
      MaxId = MaxId - 1                        ' Decrement button count.
      optButton(0).SetFocus            ' Reset button selection.
End Sub

0
 

Author Comment

by:Guillo
ID: 1433678
Thank you!
I was seasrching for a general solution aplicable for all cases. And that's is!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now