We help IT Professionals succeed at work.

Hoist the colors! We’ve added location flags to usernames sitewide, so it's easier to connect with the global community on EE. View My Profile


Align a form

chrb asked
Last Modified: 2010-04-06

I was wondering how I could align a form to the desktop, like the taskbar is align default to the bottom. I have tried form1.align:= altop; but that did not work :(


Watch Question

Use the 'Screen' object to get the desktop client size.

Form1.Top := (Screen.Height - Height) DIV 2;
Form1.Left := (Screen.Width - Width) DIV 2;
etc etc

Ian C.


This centered the window, what I wanted was to align it to the top so no other windows go over it.


If you want it at the top wouldn't you set Form1.Top := 0 ??


I want to make a bar like the taskbar, if you don't set the option to hide automaticly none program will go over it. Excactly like if have a MDI form and put a component on it and align it, other MDI child will not go over it.

(Sorry my bad english)

Now I understand what you are trying to do.  The screen or desktop is not exactly like a container (like a panel or form).  For example, if you run any pgm, it can be covered by another whether or not it is at the top of the desktop.  Let me see if there is a way to make the desktop look like it 'starts' lower (after the first pgm is running).

It sounds like you want it to Stay on Top and not be covered by any other form.  If that is what you want check out the Object Inspector for the form.  There is a property called FormStyle.  It has the option of making the form fsStayOnTop.  No other program/form will go "over" the form, they will always go "under" the form.  

Then to align it to the top of the screen use the suggestion that icampbe1 gave and do your own calculations for the size of the form based on the Screen object (screen width and height are availible).  Use Top:=0 and Left:=0 to make it at the top and then assign the Width to the Screen Width and Height to whatever you want.  

I'm not sure how to INFORM Windows that the now availible screen area is less when not hiding and regular (minus a few pixels) when the your "taskbar" is in hide mode.  That can create problems later if a user starts a program and Windows places the title bar completely under your stay on top "taskbar."  There is probably an API call to tell windows that.  The problem is finding the right one :-)  I'll search for one if I have time.

Good Luck,


Increase to 120


I have found out that I must use the shappbarmessage, but I can't get it work :(
procedure TForm1.OnCreate(Sender: TObject);
 AppBar: tAppBarData;
 I: Integer;
 AppBar.cbSize:= SizeOf( tAppBarData);
 AppBar.hWnd:= Handle;
 AppBar.uEdge:= ABE_TOP;
 I:= SHAppBarMessage( ABM_NEW, AppBar);

Please help ! Thanks !

This one is on us!
(Get your first solution completely free - no credit card required)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.