[Webinar] Streamline your web hosting managementRegister Today


adding a components in Visual Basic

Posted on 2000-01-18
Medium Priority
Last Modified: 2013-11-25

How is it possible, in visual basic, to add a component (like a rectangle) in code ?
Question by:joost_harm
  • 2
  • 2
LVL 43

Accepted Solution

TimCottee earned 60 total points
ID: 2362812
Here is an example to do just that, for more info see help: Add Method (Controls Collection)

    Dim shpOne As Shape
    Set shpOne = Me.Controls.Add("VB.Shape", "shpOne")
    With shpOne
        .Left = 100
        .Top = 100
        .Visible = True
        .FillColor = vbGreen
        .FillStyle = 7
        .Shape = 1
    End With

Expert Comment

ID: 2362820
Nope.  Not possible.

Your EXE must contain the references to your registry where to find components.  Adding references to your compiled code is not possible.

You must specify all components if you want to reference them from code later (to dynamically create a control or something)
LVL 43

Expert Comment

ID: 2362830
vindevogel, if you look at the help text you will see that it is possible to add an unreference control, it is a little bit of extra code but IS possible. Here is an extract from MSDN.

Adding Unreferenced Controls at Run Time
You can also use the Add method to dynamically add a control that is not referenced in the project. (An "unreferenced" control is a control that is not present in the Toolbox.) To do so, you must also add the control's License key to the Licenses collection as well. The example below adds a control's license key before adding the control itself:

Option Explicit
Private WithEvents extCtl As VBControlExtender

Private Sub Form_Load()
   Licenses.Add "prjWeeks.WeeksCtl", "xydsfasfjewfe"
   Set extCtl = Form1.Controls.Add("prjWeeks.WeeksCtl", "ctl1")
   extCtl.Visible = True ' The control is invisible by default.
End Sub

Note   See Add Method (Licenses Collection) in the See Also list for more information about retrieving a control's license key.

Expert Comment

ID: 2362943
Hmm, never too old to learn ...

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
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…

591 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