miky
miky

Reputation: 449

After loading my application is not completly hide in tray

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;
        }
    }

Upvotes: 0

Views: 588

Answers (3)

doneyjm
doneyjm

Reputation: 145

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

form.ShowInTaskbar = false;

Upvotes: 1

miky
miky

Reputation: 449

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.

Upvotes: 0

Romil Kumar Jain
Romil Kumar Jain

Reputation: 20775

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!

Upvotes: 0

Related Questions