0

The title is a bit vague, but my problem is this. In Microsoft visual studio im making a console application in c#, and in the code i wanted to be able to launch a windows form inside the same project. In visual basic this can be done with Application.run(formName), however if done in c# using a refrence, the windows form oppens but then immediately stops responding. What is the correct way to open a form from a console app?

class Program
{
    static void Main(string[] args)
    {

        Console.WriteLine("Enter a number");
        int x = int.Parse(Console.ReadLine());

        if (x == 3)
        {
            menu menuInstance = new menu();    //menu would be the name of the windows form
            menuInstance.Show();



        }


        Console.ReadKey();

        }
    }
}
Omada
  • 774
  • 3
  • 11
cooldudsk
  • 65
  • 1
  • 4
  • 13

1 Answers1

1

Use the same code a WindowsForms project does, Application.Run is still the way to go:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
} 

Hard to say what you did wrong with your original attempt at that, as you didn't post that code.

BradleyDotNET
  • 59,038
  • 10
  • 94
  • 113