Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating Controls  in run-time

Posted on 1998-09-08
7
Medium Priority
?
153 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
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 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 300 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

916 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