Dies liegt daran, dass Form1 das Hauptformular der Anwendung sein wird. Insbesondere wird es an die Application.Run
-Methode übergeben, die ein ApplicationContext
Objekt mit Form1 erstellt, das als Hauptformular zugewiesen wird. Wenn die Anwendung gestartet wird, überprüft es, ob das ApplicationContext
über ein Hauptformular verfügt, und wenn dies der Fall ist, wird die Visible
Eigenschaft dieses Formulars auf true
festgelegt, das das Formular angezeigt wird.
Oder in Code ausgedrückt, ist dies Application.Run
:
public static void Run(Form mainForm)
{
ThreadContext.FromCurrent().RunMessageLoop(-1, new ApplicationContext(mainForm));
}
RunMessageLoop
wird eine weitere interne Funktion rufen Sie die Nachrichtenschleife einzurichten, und in dieser Funktion finden wir folgendes:
if (this.applicationContext.MainForm != null)
{
this.applicationContext.MainForm.Visible = true;
}
Dies ist es, was Form1 zeigt.
Dies gibt auch einen Hinweis darauf, wie zu verhindern, dass Form1 Formular beim Start automatisch angezeigt wird. Alles, was wir tun müssen, ist, einen Weg finden, um die Anwendung zu starten, ohne Form1 als Hauptform in den ApplicationContext
zugewiesen ist:
ich aus dem Code
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// create the form, but don't show it
Form1 form = new Form1();
// create an application context, without a main form
ApplicationContext context = new ApplicationContext();
// run the application
Application.Run(context);
}
Danke Fredrik, wo findest du den if-Code, den du gepostet hast? – George2
Ich habe den Reflector von Red Gate benutzt: http://www.red-gate.com/products/reflector/ –
Cool, was sind die Unterschiede zwischen Show und set Sichtbar zu wahr? – George2