Search code examples
delphifullscreen

Centered, Full Screen Application


I am currently developing a fullscreen application that I want to be centered on the screen. I have set the following settings on the form:

WindowState:= wsMaximized
FormStyle:= fsStayOnTop

However due to the form height and width being much lower than the screens actual resolution, the form is aligned into the top-left corner. I have also attempted using the Position setting on the form, however none of these settings seem to have the desired outcome. They either have no effect or shift the entire maximized for towards the Bottom-Right corner, resulting in being able to see the forms behind (I hope I have described this well enough).

Thankyou


Solution

  • The way I understand your question is that the form, as such, maximises correctly, but the components are in top-left corner of the maximized form, according to their Left and Top properties as set in the form designer.

    For example, a form as designed in the designer:

    enter image description here

    Form as it appears when maximized (and this is the problem):

    enter image description here

    If my understanding of the problem is correct, the solution is to place all components on a TPanel and then center that TPanel on the form.

    There are two ways to center the TPanel
    1) Clear (set to false) all anchors of the panel as in the link provided by TLama in his comment.
    2) Center the panel in the forms OnResize event

    procedure TForm4.FormResize(Sender: TObject);
    begin
      Panel1.Left := (ClientWidth - Panel1.Width) div 2;
      Panel1.Top := (ClientHeight - Panel1.Height) div 2;
    end;
    

    Either way the result looks like:

    enter image description here