Create & delete dynamic control 
Author Message
 Create & delete dynamic control

You can create controls easy enough at run time with a Dim statement, and
remove them with the unload as in:

Dim picSomething as new Picture1
picSomething.move  <wherever>

To delete it:
    Unload PicSomething

If you need code behind the control, paint the first control on the form as
an array (set the index property).  Then any control you create from it will
inherit its code with the appropriate index property passed as a parameter.

Quote:

>Hi !

>Can someone tell me how can I create and delete a control during run
>time (e.g. PictureBox) using Visual Basic 5.0 ?
>My idea is to start up from an empty form, and load all components only
>when the program starts running. I really hope there is someone who can
>help me in solving this problem.
>Thanks in advance.

>-Pui Hua-



Thu, 01 Feb 2001 03:00:00 GMT  
 Create & delete dynamic control
You can set an object AS an other but you can't create an OCX like you
could create an excel.worsheet. So, you couldn't start with an empty
form.

You can have one timer and duplicate it: "Set MyObj = New Form1.Timer1"
and even having different events: "Set MyObj = WithEvents Form1.Timer1".
The best way I think to achieve your goal is to compile a ActiveX Dll
with a timer on it:

Declarations:
  Public Event Time

Private Sub (MyClass.)Timer1_Timer()
        RaiseEvent Time
End Sub

And then, on the project calling this Dll...

  Declarations:
        Public WithEvents MyObj as MyClass.Timer
        ' You should see a sub named MyClass_Time appear...
        ' Notice that you must check the MyClass Dll on the Project/Reference
menu of Visual Basic 5.

Private Sub Form1_Load()
  Set MyObj = New MyClass.Timer
End Sub

You now have your empty form with a Timer on it.
Hope it will help...

             Martin

Quote:

> Hi !

> Can someone tell me how can I create and delete a control during run
> time (e.g. PictureBox) using Visual Basic 5.0 ?
> My idea is to start up from an empty form, and load all components only
> when the program starts running. I really hope there is someone who can
> help me in solving this problem.
> Thanks in advance.

> -Pui Hua-



Thu, 01 Feb 2001 03:00:00 GMT  
 Create & delete dynamic control
Hi !

Can someone tell me how can I create and delete a control during run
time (e.g. PictureBox) using Visual Basic 5.0 ?
My idea is to start up from an empty form, and load all components only
when the program starts running. I really hope there is someone who can
help me in solving this problem.
Thanks in advance.

-Pui Hua-



Fri, 02 Feb 2001 03:00:00 GMT  
 Create & delete dynamic control
Thank you for the helps, my problem's finally solved !  :-)

The mistake I did previously was attempt to unload the ControlName(0) which
was created on the form during design time, thus I was prompted an error
message -- "cannot unload controls created at design time". However, this
problem is solved once I change the control's Index to be unloaded from 0
to 1 and above.

Thanx !

-Pui Hua-



Fri, 02 Feb 2001 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Creating dynamic / runtime controls in control array

2. Dynamic Resizing of a form &control based on picture size

3. Dynamic Forms: Creating Controls On The Fly

4. Dynamic creating control on userform

5. Creating Dynamic Controls (or something similar)

6. Problem on firing events of a dynamic-created control

7. How do I create dynamic controls at runtime

8. Creating dynamic User Controls/ActiveX - Help

9. How do you create dynamic controls

10. How to create dynamic custom controls in vb4?

11. how to create a dynamic array of command button control

12. Dynamic Create Control at Run Time

 

 
Powered by phpBB® Forum Software