How to display notification bar in WinForms?

You all know: "You have new answers!" notification bar on SO. I would like the same thing in shape, preferably just as smoothly. Is there an easy way? Or do I have to completely create this?

My searches didn’t come up with any good results, only a bunch of progress bars and pop-ups in the system notification area, but that’s not what I’m looking for.

The messages I want to display are specific to the form, not the entire application

+2


a source to share


5 answers


Create two panels in your form, the notification bar is docked to the top and below that the content bar is anchored to the top. In your Form .Load, set the height of the notification bar to zero. Don't set the height to zero in Design View, you won't be able to click in the notification bar to edit it.

Then, when you receive a notification, draw the content on the notification bar and create a System.Windows.Form.Timer that increases the height of the notification bar by a few pixels every few milliseconds or so. Stop when the panel is at the desired height. Do the same with negative height to hide the panel.



It doesn't require redrawing or recalculating the size or position of anything, doesn't overload anything and looks slippery. I did this and it works.

+1


a source


You can simply animate the panel to drop off the top of the form's client area.



Increase the y-coordinate of the panel in the time loop. The panel will start invisible and slowly become visible. (The panel will start at -panel.height and work its way up to 0.)

+3


a source


If you want it to be bound to a specific form, it should be enough to just put it Panel

in the form with it Dock

set to DockStyle.Top

, then place a label for the description and a button that hides it.

+1


a source


It is not difficult to do this with a panel or with a UserControl, but in this case, part of the slide will shrink as the panel slides down. To simplify this, I would use SplitContainer. The top split bar contains the notification bar and the splitter distance is initially. Move the panel into view by increasing the SplitterDistance property. Doing it this way means you don't have to worry about other form content sliding down (which is a hindrance because it prevents you from using docking).

The only downside to using a SplitContainer that I can think of is that the animation of the bar will be slightly different: the text will not scroll down with the bar, it will display in place when the bar slides down. If this bothers you, you can fix it if the text (or panel / user control) moves down as you increase the splitter distance (just a few more lines of code).

Panel display:

    for (int i = 0; i <= 33; i++)
    {
        splitContainer1.SplitterDistance = i;
        Thread.Sleep(5);
        Refresh();
    }

      

Hiding the panel:

    for (int i = 33; i >= 0; i--)
    {
        splitContainer1.SplitterDistance = i;
        Thread.Sleep(5);
        Refresh();
    }

      

Of course, if you don't mind having the notification bar just cover the top of your form, you can just make it all very simple with the bar. :)

+1


a source


I was looking for the same thing now and found this in a code project

I haven't used it yet, so I have no idea how durable it is.

0


a source







All Articles