FormAnimator class - A helper class that you can add an instance of to a form to provide animation when the form is shown, hidden or closed. Supported animations are Roll (form is unrolled and rolled up from one edge to the opposite), Centre (form unrolls from the centre out and rolls up from all edges in), Slide (form slides in and out from one edge to the opposite) and Blend (form fades in and out). Roll and Slide animations can be up, down, left, right or diagonal. To use this class just add a single line of code similar to this to your form:
CSharp Code:
private FormAnimator animator;
public Form1()
{
InitializeComponent();
this.animator = new FormAnimator(this,
FormAnimator.AnimationMethod.Slide,
FormAnimator.AnimationDirection.Up,
400);
}
NOTE: The C# Toast demo will be here soon. Watch this space.
The attached project includes a ToastForm class that uses the FormAnimator class from above to create a popup notification in the lower, right-hand corner of the screen, just above the system tray, as many commercial applications do. You can import this class into your own project as is or create your own using the same pattern.
To see the demo in action, run the attached project and click the Button on the main form several times. You'll see notification windows stack themselves up from the bottom, right-hand corner of the screen. As a new notification window slides up it pushes any existing windows further up the screen.
The notification windows are each a random height and will remain displayed for a random time period. As a window slides out of view again any windows above it will fall down to fill the vacant space.
The last point to note is that the notification window will not take focus when it's first displayed, but if you click it it will be activated.
Edit: 27-Nov-2008
Set the TopMost property of the ToastForm class to True to ensure notification windows were not hidden behind other windows if the caller is not currently active.
Last edited by jmcilhinney; Nov 26th, 2008 at 10:39 PM.
Re: Animated Window Effects with "Toast" Popup Demo
We've been trying to adapt your code so I can use it on a socket programming application I am currently working on.
The problem is that the toastform stops working and will not be able to close it, is there a possibility that the timer is creating the problem?
Here's a sample of the code I did
Code:
if( nBytesRec > 0 )
{
// Wrote the data to the List
string sRecieved = Encoding.ASCII.GetString( m_byBuff, 0, nBytesRec );
// WARNING : The following line is NOT thread safe. Invoke is
// m_lbRecievedData.Items.Add( sRecieved );
Invoke( m_AddMessage, new string [] { sRecieved } );
sliceCount += 1;
Form_Animation_and_Toast_Demo.ToastForm slice = new Form_Animation_and_Toast_Demo.ToastForm(this.rng.Next(2000, 10000), sRecieved);
slice.Height = this.rng.Next(50, 200);
slice.Show();
// If the connection is still usable restablish the callback
SetupRecieveCallback( sock );
}
The attached project includes a ToastForm class that uses the FormAnimator class from above to create a popup notification in the lower, right-hand corner of the screen, just above the system tray, as many commercial applications do. You can import this class into your own project as is or create your own using the same pattern.
I've never gone to the effort of determining which license to officially apply to the stuff I post in the CodeBank forum and the like. As long as you don't try to expressly claim it as your own, I'm happy for you to do whatever you want with it.