How should I display a notification bar in WinForms? - winforms

You all know the "You've got new answers!" notification bar on SO. I'd like the same thing in a Form, preferably just as smooth. Is there a simple way? Or do I have to completely create this myself?
My searches did not yield any good results, only lots of progress bars and popups in the system notification area, but that's not what I'm looking for.
The messages I want to display belong to a Form, not to the whole application

You could simply animate a panel dropping down from the top of the client area of the form.
Increasing the y coordinate of the panel in a timed loop. The panel would start invisible and slowly become visible. (The panel would start at -panel.height and work its way down to 0.)

Create two panels in your form, a notification panel docked to top, and below that a content panel anchored to top. In your Form.Load, set the height of the notification panel to zero. Don't set the height to zero in Design View, you won't be able to click on the notification panel to edit it.
Then when you get a notification, draw the contents in the notification panel and create a System.Windows.Form.Timer that increases the height of the notification panel by a few pixels every few dozen milliseconds or so. Stop when the panel is of the desired height. Do the same with a negative height to hide the panel.
This does not require repainting or recalculating sizes or positions of anything, does not overdraw anything, and looks slick. I have done this and it works.

If you want it constrained to a particular form, it should be easy enough to put a Panel on the form with its Dock set to DockStyle.Top, then place a label for the description and a button that hides it.

It's not difficult to do with a panel or a UserControl, but the fiddly part is making the contents of the form slide down as the bar slides down. To simplify that I would use a SplitContainer. The top splitpanel contains the notification bar and the splitter distance is initially 0. Slide the bar into view by incrementing the SplitterDistance property. Doing it this way means you don't have to worry about making the other contents of the form slide down (which is a hassle because it prevents you from using docking).
The only downside to using SplitContainer I can think of is that the animation of the bar will be slightly different: the text won't scroll down with the bar, it will be revealed in place as the bar slides down. If this bothers you, you can fix it by having the text (or your panel/custom control) slide down as you increase the splitter distance (only a couple more lines of code).
Showing the bar:
for (int i = 0; i <= 33; i++)
{
splitContainer1.SplitterDistance = i;
Thread.Sleep(5);
Refresh();
}
Hiding the bar:
for (int i = 33; i >= 0; i--)
{
splitContainer1.SplitterDistance = i;
Thread.Sleep(5);
Refresh();
}
Of course, if you don't mind the notification bar simply covering the top part of your form, then you can just do the whole thing very easily with a panel. :)

I was looking for the same thing just now and found this on code project
I have not used it yet, So I have no idea how solid it is.

Related

Flood fill text based on a percentage in silverlight splash screen

I want to create a custom splash screen where some text on the page will end up being the progress bar. I need the text to flood fill with color from left to right based on the % loaded. My first thought (since I'm not use to doing this type of UI related stuff) was to have a textblock with the forecolor being trasparent layered over something like a border with its backcolor set and then grow the border control based on the %, but this is such a hack, there has to be something better with all the wonderful things silverlight can do. I had also thought about using a image so I could outline the text, but noticed the image was slow and was the last thing to load on my splash screen.
Any ideas on the right way to acomplish this?

Is there a way to ensure that a Silverlight ScrollViewer keeps the top item completely visible

In Silverlight 4, is there a way that whenever you page down a ScrollViewer (i.e click the scroll bar in the area adjacent to the thumb) whatever item is at the top is completely visible. I still need it to scroll smoothly when the thumb is dragged or the mouse wheel is used.
My client doesn't like that an item is cut in half when he pages down the list because it is cut in half both when its at the top and when its at the bottom. I suggested some sort of integral scroll, and he didn't like it. He wants it to still scroll smoothly unless paging up or down.
Edits
Here's the catch. The items are not the same size. So I have to detect the item that is at the top of the scroll viewer and Scroll it into view. Is there an easy way to do this?
The first thing you need to do is dig out the vertical scroll bar from the internals of the ScrollViewer. You can do this with the help of VisualTreeHelper. There are a number of little chunks of code in various blogs the make its use even easier. I recommend this VisualTreeEnumeration (but I would wouldn't I). With that extensions class in place you can get the vertical scroll bar with:
ScrolBar vertSB = someScrollViewer.Descendents()
.OfType<ScrollBar>()
.FirstOrDefault(sb => sb.Name = "VerticalScrollBar");
Now you can attach to is Scroll event and determine the type of scroll that occured like this:
vertSB.Scroll += (s, args) =>
{
if (args.ScrollEventType == ScrollEventType.LargeDecrement
|| args.ScrollEventType == ScrollEventType.LargeIncrement)
{
// using args.NewValue determine the correct Integral value and assign
// using someScrollViewer.ScrollToVerticalOffset
}
};

Text marquee WinForms

I want to implement scrolling functionality in winforms. I need text to scroll like a marquee, but from the bottom to the top.
How can I do that?
The question is a bit vague, but I think what you want to do is set AutoScroll=true on your form and scrolling will be automatically provided.
I think I know what you want to do. (making a specific area scrollable)
You can do it this way:
Create a form
Drag a panel onto it.
Set the panel docking...the way you want it
Set AutoScroll = true for the panel(Eric has suggested this).
Now drag any other control onto the
the panel.
The panel area is now scrollable.
If you want to make the whole form scrollable then set AutoScroll = true for the form.
In relation to your comment to PK's answer, you'd need to simply code into a timer, or other method, to change the labels/controls Y (Or Top) value, decrementing it as required. Once it reaches -(control Height), change to (Form.Height)+(Control Height) and continue decrementing.

Get airport display type transition when data changes

A client has asked for a display to flick over like an airport display screen, ie each row flicks over when information changes.
I am not sure which is the best control to use, or the method of getting each row to transform one after the other.
any suggestions woul b gratfully accepted
John
Here's what I would do in general concept..
Make a regular panel of, say 50px high. (This is arbitrary but this panel just holds the size in place so the control doesn't shrink with its contents.)
Create a panel inside that one that will be the 'animated' panel.
When it's time for information to animate, create a storyboard that uses a transformation to "stretch" the height down to 0, change the content to the updated information, then tranform stretch the height back to 50px. This will create the illusion that the panel is flipping over.
If you make this a user control, then you could simply add however many "rows" you needed of this control to a StackPanel to make your screen.
The best way of representing this effect easily is to randomize the text during the change.
Patrick Long implemented this effect as a custom animation here

Center a Silverlight modal popup in a canvas that is larger than the screen

I currently have a Silverlight canvas that exceeds the viewable area of the screen (I'm letting the users drag the viewable areas around to navigate). I'm trying to display a modal popup that always shows up in the middle of the viewable area, and I can't seem to find any property that tells me what currently is on the screen. Basically if the user has panned down to the bottom and clicks something that causes a modal popup to appear it is stuck at the far top of the screen.
Any ideas anyone?
Thanks
~Steve
I don't think this is possible since the visibility isn't being surfaced. Perhaps with some fun JavaScript to figure out where the panning is?
Quite true. I wound up creating a holding canvas, making that full screen, and putting everything else as a child canvas within that. The modal popup now comes up in the holding canvas.
Gabriel GuimarĂ£es one works good.
App.Current.Host.Content.ActualHeight(and ActualWidth) does bring the browser size inside. Good for calculating position. And of course you can use LayoutUpdated on your main control to double check the sizes and resize stuff if need be.

Resources