Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Hide() on startup, without ShowInTaskbar to false

I am trying to make an application with hotkeys and an option to startup in the taskbar tray.

Now the problem is, that using this.Hide() in the load event, won't have any effect. I can add this.ShowInTaskbar = false, but after I set it on true again, to show the window, it disables my hotkey out of itself.

Is there an other way to hide my form on startup, or to prevent my hotkey from unregistering?

My code to hide the form:

private void frmMain_Load(object sender, EventArgs e)
{
    if (StartBG())
    {
        this.Hide();
        this.ShowInTaskbar = false;
        notifyIcon.Visible = true;
        notifyIcon.ShowBalloonTip(3000, "Kore screenshots", "The application is started and will run on the background.", ToolTipIcon.Info);
    }
}

After the code above, the hotkey still works,

private void showform()
{
    this.Show();
    this.ShowInTaskbar = true;
    notifyIcon.Visible = false;
    this.WindowState = FormWindowState.Normal;
}

After this code, the hotkey is disabled.

like image 747
Ivar Avatar asked Jan 20 '23 22:01

Ivar


1 Answers

What I've done in the past is to create a separate form, which is always minimized and ShowInTaskbar false (so it's never user visible), and this form owns the NotyifyIcon.

Then, any UI I want to display, I develop as separate forms which I show/hide as required. I find this works more cleanly than trying to get one form which might be shown/hidden/showing in taskabr/owning a notifyicon.

like image 174
Damien_The_Unbeliever Avatar answered Jan 30 '23 07:01

Damien_The_Unbeliever