Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating Controls  in run-time

Posted on 1998-09-08
7
Medium Priority
?
149 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
[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
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
Independent Software Vendors: 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!

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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

721 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