0

I have code like this:

public form()
{
    InitializeComponent();
    init(); //read ini and try to minimize
}

private void timer1_Tick(object sender, EventArgs e)
{
}

and in ini method I minimize form and hide it(in debug i can see form.visible = false), but when it leaves init method then it jumps on timer and change visible = true and i can see my app in taskbar and tray. I want see only tray icon. I use this to minimize form to tray.

So far i made this,but maybe is implemented wrong way because when form is showed form made something like refresh and it looks strange.

private void notifyIcon1_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }

    private void minimizeWindow()//this method is called on form resize
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            this.Hide();
            this.ShowInTaskbar = false;
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon1.Visible = false;
            this.ShowInTaskbar = true;
        }
    }
Community
  • 1
  • 1
miky
  • 449
  • 6
  • 20

3 Answers3

1

For hiding the window from task bar you can use ShowInTaskbar property. In your init method try this thing:

form.ShowInTaskbar = false;
Taryn
  • 242,637
  • 56
  • 362
  • 405
doneyjm
  • 145
  • 6
0

You can add a minimize event on load, if that your program is set to minimize to system tray!

Or you can add Me.Opacity = 0(Me.Opacity = 1 when clicked on systray icon again) on load, and then hide the taskbar button!

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
0

solution is simple:

        private void notifyIcon1_Click(object sender, EventArgs e)
    {
        this.Show();
        this.WindowState = FormWindowState.Normal;
    }

    private void minimizeWindow()
    {
        if (FormWindowState.Minimized == this.WindowState)
        {
            notifyIcon1.Visible = true;
            this.Hide();
        }
        else if (FormWindowState.Normal == this.WindowState)
        {
            notifyIcon1.Visible = false;
        }
    }

and

        private void AAL_Load(object sender, EventArgs e)
    {
        minimizeWindow();//call it again
    }

Dont use form.ShowInTaskbar = false; because that make many problems.

miky
  • 449
  • 6
  • 20