.NET/C# Selectively starting with hidden main form
A way to start a C# application with the main form hidden. NO flicker or conjuring of cheap tricks.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
namespace KeyGuard_Client
{
static class Program
{
private static string exepath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Start minimized if we start from InstallDirectory.
if (exepath != @"C:\InstallDir") {
Form1 MainForm = new Form1();
MainForm.WindowState = FormWindowState.Minimized;
MainForm.ShowInTaskbar = false;
Application.Run(MainForm);
} else {
Application.Run(new Form1());
}
}
}
}