Solved

Creating Controls  in run-time

Posted on 1998-09-08
7
138 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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