.NET CE 3.5 WinForm Hiding main form right after Application.Run();

196 views Asked by At

I found an answer that shows a nice technique to use in order to accomplish this, but the answer was from 2008 and it doesn't appear to be valid today?

It recommended to remove the parameter from Application.Run() in order to manually show/hide form as required. But in .NET Compact Edition 3.5, parameter must be provided.

I have the following code with no luck, form still displays. I wish to hide the main form upon the program starting.

static class Program
{
    public static Form1 MainForm = new Form1();
    [MTAThread]
    static void Main()
    {
        Application.Run(MainForm);
        MainForm.Visible = false;
        MainForm.Hide(); //Also tried this...
    }
}
1

There are 1 answers

1
Sinatr On BEST ANSWER

You don't have to use Application.Run() (with or w/o parameter):

static class Program
{
    private static Form1 _mainForm = new Form1();
    public static Form1 MainForm { get { return _mainForm; } }

    [MTAThread]
    static void Main()
    {
        // blablabla

        // do not call this until you want to show main window
        MainForm.ShowDialog();
    }
}