So, you have a dynamic GUI that must be built at runtime. It sounds
like you have one form being built, and another form in which the user
is making choices that builds things into the first form. Am I right?
I'm going to make an assumption. I'm going to assume that the form
you're building is dynamic, but not completely arbitrary. By that I
mean that the user isn't saying things like, "Place a radio button
here." Rather, the user is making some choice like "I want a topping on
my sundae" and that causes certain controls to be placed on the second
form. Probably nothing so trivial, but you get the idea.
The other possibility is that you're writing a completely
general-purpose GUI builder, in which case the following advice doesn't
apply.
I would write methods and properties on the first form (the one being
dynamically built) that are based _not_ on what controls get added, but
on _why_ they're being added. So, to continue my silly example, you
might have a method on Form1 like this:
public void AllowToppingSelection(ArrayList toppings)
{ ... }
This method the contains the code to place the correct radio buttons on
the form to select amongst the indicated sundae toppings.
The idea here is that the client form (the one asking to add controls
to the form being built) doesn't have to know how the dynamic form is
offering that selection to the user. The client is concerned with
client-side things: ice cream flavours, toppings, cone type, cone
size... stuff like that. It builds the dynamic form by telling it
_what_ the user wants, not _how_ to add the controls. This allows the
client to work in a higher level of abstraction, and leaves the
complexities of how to place controls entirely within the dynamic
form's code.
As I said, the alternative is that you're building a completely generic
GUI builder, where there is no higher level of abstraction. That's
beyond my expertise... perhaps someone else here can comment on how to
do that, if that's your case.
Guillaume BRAUX wrote:
Here is exactly what I want to do in my app :
The main problem is that my app will work with a totaly dynamic GUI, so
buttons, label and so on have to be created at runtime.
When I click on a runtime created button, I want to load a UserControl
not yet instaciated and put it on a TabPage also created at runtime
How can I achieve this goal ?
Thanks,
Guillaume
"Bruce Wood" <br*******@canada.coma écrit dans le message
news:<11*********************@h48g2000cwc.googlegr oups.com>...
Guillaume BRAUX wrote:
Perhaps an inherited form/control?
>
Already tried ... My control class inherit from my form class, but il
does
not help ... I still have to instaciate the form to be able to do a
control
add (class2.controls.add(myLabel)) ...
>
Thanks
What are you trying to do? I see questions like this posted to
newsgroups from time to time, in which the OP asks how to achieve some
effect, then after a half-dozen posts it turns out that the problem is
to set the label text at run-time, or make a label disappear at
run-time, or something like that, all of which is very easy to do using
other means.
So... could you step back a bit and tell us what you're trying to
achieve? Why do you want to add a label at runtime? What is that going
to do for you?
Perhaps there's another, much easier way to do what you want to do.