0
votes

I am developing an application that starts minimized and shown at system tray with a notify icon.

When application is running and I minimize it, form runs the Hide() method in Resize event to hide the window and it works (window is hidden from taskbar and shown the notify icon at system tray) . The problem is when the application is starting up. It is configured to run minimized.

When it starts up, the system tray icon appears and the window appears minimized, but it is shown in taskbar.

What is the problem?

This is the Resize event:

    private void frmMain_Resize(object sender, EventArgs e)
    {
        if (this.WindowState == FormWindowState.Minimized)
        {
            Hide();
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(200);
        }
    }
2
what about this.Hide();sujith karivelil
have you tried setting form's property ShowOnTaskbar to falseNino
Resize event is not being fired on startup?FINDarkside
Does that event get fired?Matteo Umili
ShowOnTaskbar allows to not display on taskbar always. I would have the same problem I guess, or even more complicated to control when to enable or disable ShowOnTaskbar property. However, I hae find a workaround on this. See the comment in the answerjstuardo

2 Answers

0
votes

I'd try putting all of that code in Load event instead of Resize:

private void frmMain_Load(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        Hide();
        notifyIcon.Visible = true;
        notifyIcon.ShowBalloonTip(200);
    }
}

Resize event is only called when the app is resized somehow manually (I understand that's why it works when you click on the minimize button but it doesn't on startup).

0
votes

Try this

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            HideWindow();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            HideWindow();
        }

        private void HideWindow()
        {
            if (this.Visible == true)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    this.Hide();
                }
            }
        }
    }
}