C# class help? [modified]
-
I would like to create a new instance of a class, but I would like the user to tell me the name of the object they want to create, and the code uses that (stored as a string) name and creates the object. This is done as a method. This is what I thought about, but it creates it called the name of the variable: public void createTextBox(string textBoxName) { // Create a new text box TextBox = textBoxName new TextBox; } I am going about this all wrong! OK, what I want to do, is create a DLL, that is for a programming language created with C#, that allows them the make a GUI, they can create different components, how do I do this? -- modified at 7:05 Wednesday 14th February, 2007
-
I would like to create a new instance of a class, but I would like the user to tell me the name of the object they want to create, and the code uses that (stored as a string) name and creates the object. This is done as a method. This is what I thought about, but it creates it called the name of the variable: public void createTextBox(string textBoxName) { // Create a new text box TextBox = textBoxName new TextBox; } I am going about this all wrong! OK, what I want to do, is create a DLL, that is for a programming language created with C#, that allows them the make a GUI, they can create different components, how do I do this? -- modified at 7:05 Wednesday 14th February, 2007
This is not possible, a variable name needs to be hard coded, but you can use an ArrayList to store an unkown number of TextBoxes.
-
I would like to create a new instance of a class, but I would like the user to tell me the name of the object they want to create, and the code uses that (stored as a string) name and creates the object. This is done as a method. This is what I thought about, but it creates it called the name of the variable: public void createTextBox(string textBoxName) { // Create a new text box TextBox = textBoxName new TextBox; } I am going about this all wrong! OK, what I want to do, is create a DLL, that is for a programming language created with C#, that allows them the make a GUI, they can create different components, how do I do this? -- modified at 7:05 Wednesday 14th February, 2007
This would be possible with a Dictionary, in which case you can have a name associated with each created textbox. Just make sure you don't overwrite any existing values (with, for example, the ContainsKey() method). Just out of curiosity, why do you want to have a textbox associated with a name?
Internet - the worlds biggest dictionary
-
I would like to create a new instance of a class, but I would like the user to tell me the name of the object they want to create, and the code uses that (stored as a string) name and creates the object. This is done as a method. This is what I thought about, but it creates it called the name of the variable: public void createTextBox(string textBoxName) { // Create a new text box TextBox = textBoxName new TextBox; } I am going about this all wrong! OK, what I want to do, is create a DLL, that is for a programming language created with C#, that allows them the make a GUI, they can create different components, how do I do this? -- modified at 7:05 Wednesday 14th February, 2007
I'm assuming that what you are asking is how can a user make a form dynamically by adding controls to it. To do this, you need to add items to the forms Control collection. If you want to see an example of this, just take a look inside a form you have created in Visual Studio.NET. Take a look inside the InitializeComponent method to see what needs to be done. (Note though, setting up a control is about more than just adding it to the collection. You need to set it's location, set it's name (and so on).) If you have a control container (e.g. a Panel), then you would add any child controls of this to the controls Control collection. I hope that this gives you enough of a hint about how to get started.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.