My Photo
Name:
Location: Bangalore, India
Google

Tips to Reduce Abdominal Fat!

Friday, October 28, 2005

Create Controls on the fly...

Create Controls at Run time in VB6

You can create a control at run time in vb6 and add it to a form. But to do this you should be aware of the progid of the control to be created. ProgIDs are defined as direct sub keys of the top-level HKEY_CLASSES_ROOT key in the registry. You set the properties of the controls once it is created.

The following function creates a Label object and add it to a form.

Public Sub addLabel(frmCurrent As Form)
Dim lblFoo As Label

Set lblFoo = frmCurrent.Controls.Add("VB.Label", "lblFoo")

With lblFoo
.Left = 100
.Top = 100
.Caption = "Just Created"
.Visible = True
End With
End Sub


Load Controls at Run time in VB6

To add controls at run time, there must already be at least one instance of the control on the form and it must be part of a control array.

When the program runs, you add additional controls with the Load statement: Load ControlName(Index).

ControlName refers to the Name property of the control array you created and Index is the Index property of the new control. You should start at 1 because Index 0 is already taken by the control you placed on the form at design time.

Each control that you add in this way initially has the same properties as the original control. You'll have to position the control to prevent all the added controls from displaying at the same position on screen and set visible property to True.

1 Comments:

Blogger Muhamad Farhan said...

I want to make webbrowser control in vb6 on the fly
can I do this ?
Dim browser(5) As WebBrowser
Dim i As Integer
For i = 0 To 5
browser(i).Navigate "some url"
Next i

3:52 PM  

Post a Comment

<< Home