• 0

[C#] Start application minimized


Question

Hello,

I've made a small applicaiton and added a system trya icon. Now I'm trying to make my applicaiton start minimized, if I specify a command line argument. I've got this code at the moment:

static void Main(string[] args)
{
	Application.EnableVisualStyles();
	Application.SetCompatibleTextRenderingDefault(false);
	Form1 form1 = new Form1();
	if (args.Length == 1 && (args[0] == "/minimized" || args[0] == "-minimized"))
		form1.Visible = false;
	Application.Run(form1);
}

However, it doesn't work. But if I change "form1.Visible = false;" in that code to something different like "form1.WindowState = FormWindowState.Minimized;", then it starts the applicaiton minimized, but not minimized to the system tray.

Why doesn't this work?

Any help is appreciated greatly. Thanks.

Link to comment
https://www.neowin.net/forum/topic/428833-c-start-application-minimized/
Share on other sites

3 answers to this question

Recommended Posts

  • 0
  BigCheese said:

Hello,

I've made a small applicaiton and added a system trya icon. Now I'm trying to make my applicaiton start minimized, if I specify a command line argument. I've got this code at the moment:

static void Main(string[] args)
{
	Application.EnableVisualStyles();
	Application.SetCompatibleTextRenderingDefault(false);
	Form1 form1 = new Form1();
	if (args.Length == 1 && (args[0] == "/minimized" || args[0] == "-minimized"))
		form1.Visible = false;
	Application.Run(form1);
}

However, it doesn't work. But if I change "form1.Visible = false;" in that code to something different like "form1.WindowState = FormWindowState.Minimized;", then it starts the applicaiton minimized, but not minimized to the system tray.

Why doesn't this work?

Any help is appreciated greatly. Thanks.

Visible won't work because the form's handle hasn't yet been created. It is only created when Show() is called, which is called when the Run method invokes it. So, what you need to do is set the WindowState to Minimized and handle the VisibleChanged event. Test if the window state is minimize in your handler, then you set the visibility of the form to false.

  • 0

If you have a Tray Icon and you don't want to see the app in the taskbar, use form1.Hide() and then form1.Show() to show it again whenever you need to. I have found it difficult sometimes to get it to start in the tray. I'm sure there is a better way, but in the past I have set a timer to 1 millisecond after onload, and then called this.Hide(). It's a while since I did this though, so I may have found a better way at some point, but I don't remember it atm.

  • 0
  weenur said:

Visible won't work because the form's handle hasn't yet been created. It is only created when Show() is called, which is called when the Run method invokes it. So, what you need to do is set the WindowState to Minimized and handle the VisibleChanged event. Test if the window state is minimize in your handler, then you set the visibility of the form to false.

Thanks, that works fine.

I can see the app in the taskbar for a split-second before it goes to the system tray, but I suppose it doesn't really matter.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • The Start menu is a defining UI element that made Windows, well, Windows. naturally people will be worked up to any changes it receives.
    • I believe voice assistants have reached a dead end in terms of usability. You can only do so much with voice. Even Google is sidelining Google Assistant for Gemini. Once you can no longer shoehorn "AI" everywhere, the industry will move on to the next fancy trend try to push voice assistants to use that tech.
    • Gemini in Google Sheets can now generate fully editable charts by David Uzondu Back in January, Google introduced a feature in Google Sheets powered by Gemini that lets you ask the AI to create charts from your data. The problem was, these charts were just static pictures, slapped on top of your cells. You could not edit them, and they would not update if your data changed. Now, the company has upgraded the feature so you can edit the charts however you want, plus they stay synced with your data as it changes. The process is quite straightforward. You use the Gemini side panel and just type what you want, like "create a bar chart showing campaign performance by market." Gemini then builds the chart, and when you insert it, the chart appears in a completely new tab within your spreadsheet. From that new home, you have total control. You can change the title, tweak the colors, and adjust all the little details just like any normal chart you would build yourself. It is not a completely perfect system, however. The biggest catch is that the editable chart is linked to the data in that new tab, not your original data source. So if you want the chart to reflect new numbers, you have to update the data in the chart’s dedicated tab. This is a bit of a weird detour from how standard Sheets charts have always worked, where they update directly from the source cells. For certain, more complex chart types, Google also notes that Gemini might still fall back to spitting out a static image, so your mileage may vary. The full rollout began recently, with Google expecting it to reach everyone within one to three days. This update is available for a bunch of Google Workspace accounts, including Business Standard, Business Plus, Enterprise Standard, and Enterprise Plus. It is also included for anyone with a Google One AI Premium plan, which the company has since renamed to Google AI Pro and Ultra. If you are on one of the old Gemini Business or Enterprise add-ons that Google stopped selling back on January 15, 2025, you get this feature too. Just make sure your admin has the "Smart features and personalization" setting turned on, or none of this will work.
    • iOS feature updates are lacklustre. I know it’s difficult with a mature OS, but imagine the announcements without Liquid Glass. Pretty thin.
  • Recent Achievements

    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
    • Collaborator
      Carltonbar earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      506
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      237
    4. 4
      +Edouard
      201
    5. 5
      snowy owl
      162
  • Tell a friend

    Love Neowin? Tell a friend!