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
a source to share
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.
a source to share
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. :)
a source to share
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.
a source to share