Dynamically creating form controls

V

Vanyok

Hi everyone :)
I'm a newb to C-Sharp but more I learn about it - more I like it.
I need some help please. I'm trying to find out to dynamically allocate
form controls. For example I want to have 5 combo boxes on my form and
I want to put the into an array.
Can someone point me to some good guide on how to do it or posibly post
'how to' ?
Thanks in advance.
 
B

Bruce Wood

Vanyok said:
Hi everyone :)
I'm a newb to C-Sharp but more I learn about it - more I like it.
I need some help please. I'm trying to find out to dynamically allocate
form controls. For example I want to have 5 combo boxes on my form and
I want to put the into an array.
Can someone point me to some good guide on how to do it or posibly post
'how to' ?

There's really no need for a guide. Here's how.

Create your form, and add a couple of combo boxes using the Visual
Studio Designer. Now, switch to Code view. If you're using VS2003, open
the region of your C# file that says "Windows Form Designer generated
code" and look at what the Designer did for you. If you're using
VS2005, you have to find the partial class file that the Designer
generated and look at the code in there.

Once you've studied that code a bit and figured out what it does, just
cut and paste it into your application (e.g. the constructor of your
form, or the OnLoad method if you need to do something more intensive),
and adapt it to your needs.

I never to try to write code from scratch to put controls on the form
dynamically. Instead, I just find some Designer-generated code that is
sort of like what I want to do, copy, paste, and tweak. That way I know
it's right from the outset.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top