Link to home
Create AccountLog in
Avatar of panJames
panJames

asked on

Form from an old project becomes my new main form

Hello experts :-)

I have a new project with windows form as the main form.

I also have an old project with some windows form there.

I would like to make a form from an old project to become main form of a new project.

How can I do it?

thx!

panJames
Avatar of Erick37
Erick37
Flag of United States of America image

From the solution explorer in your new project: right click the project and select Add > Existing Item.  Navigate to the form you want to import and select it.  Click Add.

To make it the startup form, open the Program.cs file and modify the following to open your new form:
Application.Run(new Form1());
I agree with what Erick37 said.. Just Call the target Form's Object inside Application.Run() Method as a parameter.. That should start up the target Form first at runtime. Adding the form is easy via solution explorer..using Add Existing Item Option..
//Inside Program.cs file 
[STAThread]
public static void Main()
{
    Application.Run(new targetForm()); //call ur target Form here..
}

Open in new window

Avatar of panJames
panJames

ASKER

I am using SharpDevelop.

Added Form1.cs to my project.

This is my code:

private static void Main(string[] args)
            {
                  Application.EnableVisualStyles();
                  Application.SetCompatibleTextRenderingDefault(false);
                  //Application.Run(new MainForm());
                  Application.Run(new Form1());
            }

I get error message:

The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) (CS0246) - C:\Users\panJames\Documents\SharpDevelop Projects\MyProject\MyProject\Program.cs:28,24

Any hints?

thx

panJames
Replace "Form1" with the class name of the form you want to run at startup.
Erick37:

//Application.Run(new MainForm()); //it was an old form
Application.Run(new Form1());        //<- it is a new form

panJames
ASKER CERTIFIED SOLUTION
Avatar of Erick37
Erick37
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
//Also dont forget to add reference to the .exe file generated from old project by going to solution explorer clicking on project then right clicking it and selecting add reference option.. After browsing the path and selecting the old compiled .exe file u can add the above using code..