简体   繁体   中英

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

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...
    }
}

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM