Mega Code Archive

 
Categories / Delphi / Examples
 

Minimizing, maximizing and restoring any control

Title: Minimizing, maximizing and restoring any control Question: Is it possible to minimize, maximize and restore controls other than forms? Answer: Yes, and you just have to follow the 'recipe': -Drop a TMainMenu onto a form, add 3 menu items: 'Minimize', 'Maximize', and 'Restore'; -Drop a TButton onto the form; -Write the following event handlers for the OnClick event of the menu items: {--snip--} procedure TForm1.Minimize1Click(Sender: TObject); begin ShowWindow(Button1.Handle, SW_SHOWMINIMIZED); end; procedure TForm1.Maximize1Click(Sender: TObject); begin ShowWindow(Button1.Handle, SW_SHOWMAXIMIZED); end; procedure TForm1.Restore1Click(Sender: TObject); begin ShowWindow(Button1.Handle, SW_RESTORE); end; {--snip--} Run the application, and there you have it: the button can be minimized, maximized and restored, via the menu items. Note that maximizing the button is different from aligning it to the client, since when you maximize it, there is the default window maximizing animation. As you can see, we just bypassed the VCL encapsulation and used directly the WinAPI function ShowWindow to control the button. This trick can be used with any control that has a handle; thus it can't be used with SpeedButtons (they derive from TGraphicControl). A good idea would be to simulate MDI using TPanels; you would have a prototype of an MDI app without the overhead that MDI brings with itself.