Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Question about referencing a control at runtime
Message
De
28/02/2004 20:56:20
 
 
À
28/02/2004 20:22:58
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00881833
Message ID:
00881838
Vues:
20
Kevin,

>I know that Rick Strahl has the stuff on his site for dynamic code evaluation, and was wondering if that's the way to go, or if there's a simpler way.<

Nope, no simpler way ... you'll have to use reflection. Check out Rick's stuff ... I think his article has more than you will need if you're simply adding a control (I think he does stuff with getting method names and all, which it doesn't sound like you'll need). You'll basically just need to use the System.Reflection.Assembly.LoadFrom(...) and the .CreateInstance(...). But, anyway, definitely read his article.

~~Bonnie

>I have a situation where I need to dynamically add a container onto a form, where I won't know the name of the container at designtime.
>
>If I knew that the name of my container is UserControl1, I'd be doing something like the following in my form...
>
>UserControl1 oControl = new UserControl1();
>oControl.BringToFront();
>oControl.Refresh();
>
>this.Controls.AddRange(new System.Windows.Forms.Control[] {
> oControl});
>
>
>I'm writing this code as generic code in a form class, so I won't know the name of the container. I know that Rick Strahl has the stuff on his site for dynamic code evaluation, and was wondering if that's the way to go, or if there's a simpler way.
>
>Thanks,
>Kevin
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform