tags:

views:

211

answers:

2

I want to make form default as invisible. when user double click on tray icon then it should be visible showing data from database. How do i do such thing in C#. I made system tray icon but when i run a project it also shows my form with blank values. Thanks in advance.

My tray icon is on same form.

A: 

I assume you are using WindowsForms and have created the tray icon using the NotifyIcon class. Set your forms Visible property to False in the designer. This will cause the form to start as hidden.

Then in your Tray Icons Click og DoubleClick event handler set your forms Visible property for True to show it. Alternatively you can create a new instance of the form class here and show that.

Rune Grimstad
+1  A: 

Tinkering with the Visible property doesn't work, the Application class forces it on so the form initializes itself properly. You can however override SetVisibleCore() to customize behavior. Paste this code into your form:

bool mLoaded;

protected override void SetVisibleCore(bool value) {
  if (value && !mLoaded) {
    this.CreateHandle();   // Ensure the Load event runs
    value = false;         // Keep invisible
    mLoaded = true;
  }
  base.SetVisibleCore(value);
}
Hans Passant