1

I need to hide my Form at startup of the operating system(windows 7).
To accomplish that, I tried the solution:-

if (Program.Args == "/startup")
{
    this.Hide();
    this.ShowInTaskbar = false;
}

I had the above code in my form1_Load Event, Program.Args is the command line argument supplied to my program.

What is wrong in the above code?

How can I accomplish hiding of my form through command line arguments?

As some people suggested to use
this.WindowState = FormWindowState.Minimized
this.ShowInTaskbar = false I tried it but my application freezes, like this:-

enter image description here

If I comment out the line
this.ShowInTaskBar = false
it runs normally but shows the icon in task bar.

Normal Look of the application is :-

enter image description here

dbc
  • 104,963
  • 20
  • 228
  • 340
Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
  • Your code seems correct, Just put a break-point at if block and check whether your argument is correct or not. – Mohammad Arshad Alam Feb 06 '14 at 06:01
  • I guess it is the only form you have. Then it is a main form. This might help http://stackoverflow.com/questions/8764745/how-to-hide-the-mainform-and-still-run-the-program http://stackoverflow.com/questions/70272/single-form-hide-on-startup – Pavel Voronin Feb 06 '14 at 06:05
  • @Arshad I double checked, my command line arguments are correct. – Pratik Singhal Feb 06 '14 at 06:05
  • are you wanting no visibility at all like a silent mode, or if it briefly shows is that alright? – Mark Hall Feb 06 '14 at 06:10
  • No, I want that only it's icon should be visible in the notification tray and the form should not be visible to the user unless he clicks on the icon in notification tray – Pratik Singhal Feb 06 '14 at 06:12
  • See this [SO Question](http://stackoverflow.com/questions/2978597/how-do-i-launch-net-windows-forms-application-with-no-visible-windows) it appears that if you set forms WindowState to minimized and to not be shown in taskbar it will work. – Mark Hall Feb 06 '14 at 06:15
  • @MarkHall I tried your solution, but it is not working, please see the edited question. – Pratik Singhal Feb 06 '14 at 07:01
  • Try it in your forms constructor after InitializeComponent. – Mark Hall Feb 06 '14 at 07:16
  • @MarkHall It's already in my forms constructor – Pratik Singhal Feb 06 '14 at 07:18
  • Why are you setting `ShowInTaskbar` to false *when you're hiding the form*? It's not going to show in the taskbar (or alt+tab menu) when it's hidden. – Luaan Jan 24 '17 at 12:48

3 Answers3

0

Try Something like changing the visibility. I get an error code on your code because of conversion of Args to string ... but this works just fine.

private void Form1_Load(object sender, EventArgs e)
{
    this.Visible = false;
    this.ShowInTaskbar = false;
}
Surya Narayan
  • 558
  • 2
  • 16
Ronnie
  • 239
  • 2
  • 9
0
    private void Form1_Load(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Minimized;
        this.ShowInTaskbar = false;
    }

Then create a icon for the tray and show tray icon

Ronnie
  • 239
  • 2
  • 9
  • It's freezing the application, check the edited question – Pratik Singhal Feb 06 '14 at 07:03
  • @ps06756 Using the designer for Visual Studio, can you F11 through and see if it is freezing up in the designer by where the reference is placed for the load event. is it getting stuck there when it is loading your application deigner? – Ronnie Feb 06 '14 at 20:05
0

In the properties of the form (in VS) set next properties :

  • ShowInTaskbar = false
  • WindowState = Minimized

Best do this in the design form of VS not in the load event. If you are application is still freezing then please remove all other code except the clicking event on the notification icon to show the window. I simulate it with a clean form (only a button on it) and did not have a freezing problem. Here is the code that you have to execute when the user click on the notification icon:

WindowState = FormWindowState.Normal;
haldo
  • 14,512
  • 5
  • 46
  • 52