Solving (string) and creating the screen - Ex.: CreateScreen("screenTest")
-
Friends, I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen. Example: I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name. Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help. Success for All
-
Friends, I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen. Example: I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name. Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help. Success for All
-
Friends, I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen. Example: I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name. Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help. Success for All
-
Have you tried a switch statement?
switch(inputname){
case "Screen1": Screen1 s1 = new Screen1();
s1.ShowDialog();
break;case "Screen2": Screen2 s2 = new Screen2();
s2.ShowDialog();
break;// continue
default: // add a default situation.
break;
}V.
-
-
Friends, I hope you can help me. I am developing a new project and this project I have several screens. Well, I would like to create a screen through her name and that name is the same class name of the screen. Example: I create a new screen, and put her name as formCadastro. Now, in my base form, I would go to a function the string value "formCadastro" function and open the screen with the same name. Is it possible? I tried to work a little with the System.Windows.Forms.Form class but I could not ... Thank you for your help. Success for All
I would use something like this...
private void CreateScreen(string FullName, params object\[\] args)
{
Type t ;
Form f;
t = Type.GetType(FullName);
if (t != null) {
f = Activator.CreateInstance(t, args) as Form;
if (f != null) {
f.Show();
}
}
}This would also allow you to pass arguments to the constructor. You may also have to pass the Full name of the Form including the Namespace. I don't remember how Type.GetType() works. Edit: Sorry, forgot I was in C#.
modified on Monday, February 8, 2010 11:02 AM
-
I would use something like this...
private void CreateScreen(string FullName, params object\[\] args)
{
Type t ;
Form f;
t = Type.GetType(FullName);
if (t != null) {
f = Activator.CreateInstance(t, args) as Form;
if (f != null) {
f.Show();
}
}
}This would also allow you to pass arguments to the constructor. You may also have to pass the Full name of the Form including the Namespace. I don't remember how Type.GetType() works. Edit: Sorry, forgot I was in C#.
modified on Monday, February 8, 2010 11:02 AM