Guest Andrejko Posted June 10, 2002 Posted June 10, 2002 Does anyone know of a way to reference a class (say, a form class) by a String representation of its name? IE, System.Windows.Forms.getFormByName("Form1").someMember (pseudocode) would be equivalent to just saying Form1.someMember Note: I am not trying to reference an instance of a class, but a Shared (static) member of that class. Quote
*Gurus* divil Posted June 10, 2002 *Gurus* Posted June 10, 2002 You can't reference an instance of a form by it's name at the best of times, let alone if all you have is a string. Consider a public hashtable, with which you could associate text with your form instances. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Andrejko Posted June 10, 2002 Posted June 10, 2002 Shared members Actually, I would like to acces Shared members of the form (I should have stated that in my original post) I do not need an instance of the class to do this. So, Form1.someMember is entirely possible, IFF someMember is declared as Shared. Now it would be nice if I could do this with a string, without a big Select statement. A hashtable would not work, since, as I am not creating instances of the classes, I would have nothing to place in it. Good idea though. Quote
*Gurus* divil Posted June 10, 2002 *Gurus* Posted June 10, 2002 Oh ok. To create an instance of any class in your app with a string, use this code: Dim X As Form X = CType(System.Reflection.Assembly.GetExecutingAssembly.CreateInstance("MyNameSpace.Form1"), Form) X.ShowDialog() I know this isn't exactly what you wanted but it's a start, and just off the top of my head. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Guest Andrejko Posted June 10, 2002 Posted June 10, 2002 thx Thanks, this actually is a usefull piece of information. Although this code still creates an instance, instead of just referencing the class. (Static class) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.