Re: Adding controls programmatically

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Douglas Marquardt (no_spam_at_dummy.com)
Date: 05/19/04


Date: Wed, 19 May 2004 07:19:52 -0600

Hi Paul:

I suggest you use a Control Array and the Load method
instead of the Add method.

Actually, why load the controls in the form load event --
why not just load them in the IDE as part of a control array?

Doug.

"Paul Rocca" <paul.rocca@audiosoft.co.uk> wrote in message news:c8f94t$ohg$1$8300dec7@news.demon.co.uk...
> I would like to add an array of 10 OCX controls programmaticaly to my form.
> So I create an array variable of the ocx type and then populate it in my
> form load
> event using Controls.Add(....).
> This is all well and good, the controls appear and work and I can set their
> properties
> and generally interact with them.
> But I would like to get events from them and I can't seem to get this to
> work. I tried
> declaring the variable as 'With Events' but it didn't seem to like the fact
> that the variable
> is an array and now I'm a bit stumped. Any ideas?
>
> TIA
>
> Paul
>
>



Relevant Pages

  • Re: Delete controls at run time?
    ... My code creates an array of check boxes at run time based on the results of a query using this code: ... My problem is that the second time I try this I get a message telling me that it can't create the controls because they already exist, ... Is there a way to remove these check boxes programmatically when I'm done with them? ... You can Unload them or you can revise your creation code to not load them if they are already there. ...
    (microsoft.public.vb.syntax)
  • Re: Add array of controls dinamically
    ... The approach with Load need to insert the desired control with Index ... > There's simply no support for dynamically adding an array of controls. ...
    (microsoft.public.vb.general.discussion)
  • Re: Delete controls at run time?
    ... My code creates an array of check boxes at run time based on the results of a query using this code: ... My problem is that the second time I try this I get a message telling me that it can't create the controls because they already exist, ... Is there a way to remove these check boxes programmatically when I'm done with them? ... You can Unload them or you can revise your creation code to not load them if they are already there. ...
    (microsoft.public.vb.syntax)
  • Loading a form cleanly
    ... I load the values from the dataset during the Form Load. ... First the text of the combo boxes appear, then the controls and then the ... Plus, everytime I switch to a new tab on the tab control, the same ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Dynamically creating a control array
    ... I'm modifying the height of the form depending on how many controls I load. ... you can't create a true control array at runtime. ... > control array and adds the required Index param to the event procedures ...
    (microsoft.public.vb.controls)