Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i have formname in string varible .i want to form by string in C#
(convert string to Form in C#)

Regards
S.Murugesan
Posted

<br />
string formName = "MyFormName";<br />
Form myForm = System.Windows.Forms.Application.OpenForms[formName];<br />
 
Share this answer
 
v2
S.murugesan wrote:
i have formname in string varible


If this is a name of your form class then you could use something like:
// If the class name is stored in "formClass" string variable
Type formType = Type.GetType(formClass);
Form myForm = (Form)Activator.CreateInstance(formType);


This approach could be used if your form is not created.
If your form is already created then see the post from Kemo72000.

Regards
 
Share this answer
 
v3
S.murugesan wrote:
(convert string to Form in C#)


:omg: :omg:

What are you talking about ?

Do you mean to show the string content in the form ?

If so, just create a label and expose it through some property.
public string MyLabel
{
 get{ return this.Label1.Text;}
 set { this.Label1.Text = value; }
}

Now from your form,
MyForm f = new MyForm();
f.MyLabel = mystring;


I hope this is what you wanted.
:thumbsup:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900