Realization of adaptive form in Delphi

Source: Internet
Author: User

We know that the screen resolution settings affect the layout of the form, assuming that the screen resolution on your machine is 800*600, and eventually the machine resolution to distribute the application is 640*480, or 1024*768, so that the form you originally designed will become distorted on the new machine. At this point you will want the form to adapt to the different resolution, there are two ways for you to refer to.

Automatically redraw forms and controls according to the new resolution

First, define two constants in the interface section of the form, representing the width and height (in pixels) of the screen at design time. In the form's Create event, first determine whether the current resolution is the same as the design resolution, and if different, the scale procedure that invokes the form can adjust the width and height of the controls in the form again.

Const
Orignwidth=800;
Orignheight=600;
procedureTForm1.FormCreate(Sender:TObject);
begin
scaled:=true;
if(screen.width<>orignwidth)then
begin
height:=longint(height)*longint
(screen.height)divorignheight;
width:=longint(width)*longint
(screen.width)divorignwidth;
scaleby(screen.width,orignwidth);
end;
end;

The scale process adjusts the width and height of the control and automatically resizes the control font to fit the new resolution, but it does not change the position of the control's vertex coordinates, that is, the process does not change the relative position between controls. To adjust the relative position of the selection between controls, you also need to programmatically implement them, and interested readers can try.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.