neli
neli

Reputation: 45

How to make a form always top of taskbar

I want create a form in C# that always be on top of taskbar and other programs. I try with Topmost but when I click on Alt+Tab or start button on keyboard, taskbar is top of my form.

Upvotes: 3

Views: 1822

Answers (2)

Daniel
Daniel

Reputation: 813

Alexander's Timer approach from the other solution could have worked. Here's my ugly but working approach, very similar to his:

new Thread(() => { KeepOnTop(); }).Start();


private void KeepOnTop()
{
    while (!this.Disposing && !this.IsDisposed)
    {
        try
        {
            this.Invoke(this.BringToFront);
        }
        catch { }
        Thread.Sleep(100);
    }
}

In the Timer example from the other answer, instead of setting TopMost = true inside the timer tick, you should've called BringToFront(), and of course made sure the time is set for recurring ticks.

This will keep the form over the taskbar, it will not keep it over the start menu though.

Upvotes: 0

Alexander Petrov
Alexander Petrov

Reputation: 14231

Ugly approach: use Timer.

private void timer1_Tick(object sender, EventArgs e)
{
    this.TopMost = true;
}

Better not to do so.

Upvotes: 0

Related Questions