Title: Hide, Slide And Fade Away Controls On A Delphi Form
In most complex form designs you would have some panels that a user can make visible or hidden. Maybe some controls on some other container controls (like TPanel, or TGroupBox) should be made invisible due to some reasons.
If using the TSplitter control to divide the client area of a form into resizable panes, you also want some panes to be visible or not.
How About Hiding Using Sliding?
A simple "Panel1.Visible := false;" will make a panel invisible, but why not make it more eye candy by providing a hiding animation.
The AnimateWindow API function enables you to produce special effects when showing or hiding windows. There are four types of animation: roll, slide, collapse or expand, and alpha-blended fade.
Now, don't read the above by thinking that "windows" means "forms". In Windows development "window" also means any control that has a handle. Since all Delphi control that inherit from TWinControl (like Button, Panel, GroupBox, ListBox, EditBox, ...) do have a handle - they are all "windows" to the AnimateWindow API call.
Defined in windows.pas (therefore here for us to use it), the AnimateWindow has the following declaration:
function AnimateWindow(hwnd : HWND; dwTime : DWORD; dwFlags : DWORD);
The first parameter in the "window" handle. If we are to animate a panel, the first parameter would be "Panel1.Handle". Second parameter, dwTime, is the time it takes to play the animation, in milliseconds. Typically, an animation takes 200 milliseconds to play. Finally, dwFlags defines the type of animation.
Check out Windows API documentation for the possible values to dwFlags.
Anyway, here's how to slide a panel from bottom to top and hide it:
AnimateWindow(Panel1.Handle, 200, AW_VER_NEGATIVE OR AW_SLIDE OR AW_HIDE);
Here's how to make the panel appear to collapse inward:
AnimateWindow(Panel1.Handle, 200, AW_CENTER OR AW_HIDE);
That's it. Check all the sliding and fading options and make your panels hide or unhide more eye candy ;)
Thanks to Evert Etienne here's a sample application to demonstrate all AnimateWindow possibilities.
This is a demo to demonstrate the Windows API call 'AnimateWindow' which enables you to produce special effects when showing or hiding windows (forms or controls).