Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Realization method of self-adaptive form in DELPHI

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "the realization method of adaptive form in DELPHI". In daily operation, I believe that many people have doubts about the implementation of adaptive form in DELPHI. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "the realization method of adaptive form in DELPHI". Next, please follow the editor to study!

Preface

We know that the setting of the screen resolution affects the form layout, assuming that the screen resolution on your machine is 800cm 600, and the final machine to distribute the application is 640cm 480, or 1024cm 768, so the form you designed is bound to be out of shape on the new machine. At this point, you must want the form to adapt to different resolutions. Here are two ways to refer to it.

Realization method

1. Automatically redraw forms and controls according to the new resolution

First define two constants in the Interface section of the form unit that represent the width and height of the screen at design time (in pixels). In the Create event of the form, first determine whether the current resolution is the same as the design resolution, and if not, the SCALE process of calling the form can re-adjust the width and height of the controls in the form.

Const

Orignwidth=800

Orignheight=600

ProcedureTForm1.FormCreate (Sender:TObject)

Begin

Scaled:=true

If (screen.widthorignwidth) then

Begin

Height:=longint (height) * longin (screen.height) div orignheight

Width:=longint (width) * longint (screen.width) div orignwidth

Scaleby (screen.width,orignwidth)

End

End

While adjusting the width and height of the control, the SCALE process also automatically adjusts the font size of the control to adapt to the new resolution, but the only drawback is that it does not change the vertex coordinate position of the control, that is, the process does not change the relative position relationship between the controls. If you want to adjust the relative position of team selection between controls, you still need to implement it by yourself, and interested readers can give it a try.

Second, change the machine resolution to the resolution at design time

This approach does not change the form itself, but changes the screen resolution to the same resolution used when the form was designed. It needs to use the WINDOWSAPI functions EnumDisplaySettings and ChangeDisplaySettings, the former takes the current display mode information, and the latter changes the display settings. For the meaning of the specific parameters, please see DELPHI help. The definition of width constant and height constant at design time is shown in method 1.

ProcedureTForm1.FormCreate (Sender:TObject)

Var

Devmode:tDevicemode

Begin

If screen.widthorignwidth then

Begin

If EnumDisplaySettings (nil,0,devmode) then

Begin

Devmode.dmfields:=dm_pelswidthORdm_pelsheight

Devmode.dmpelswidth:=orignwidth; {width}

Devmode.dmpelsheight:=orignheight; {height}

ChangeDisplaySettings (devmode,0); {change settings}

End

End

End

At this point, the study on "the implementation of adaptive forms in DELPHI" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report