Delphi 7:应用程序扩展
我在屏幕分辨率为 1280x800 的笔记本上开发了一个应用程序。现在我想在分辨率为1600x1200的台式电脑上使用它。
当然,在台式电脑上它就太小了。我已经设置了尺寸,以便我可以在笔记本上看到整个表格。但在台式计算机上,所有内容都应该调整大小。
但在大屏幕上,事物不应该被看得更大,这意味着可以显示相同数量的信息。事物应该获得更高的高度和宽度值,以便可以显示更多信息。
在复杂的代码中,我的意思是这样的东西,它应该在创建表单(OnCreate)时自动运行一次:
devResolutionX := 1280;
devResolutionY := 800;
useResolutionX := 1600; // how to get / read out this property?
useResolutionY := 1200; // how to get / read out this property?
Form1.Height := Form1.Height+devResolutionY-useResolutionY;
Form1.Height := Form1.Width+devResolutionX-useResolutionX;
// do that with all components which makes this approach complicated
我必须使用什么才能达到该目标?
- ScaleBy
- 对齐
- 锚点
非常感谢您!
On my notebook with a screen resolution of 1280x800 I've developed an application. Now I want to use it on a desktop computer with a resolution of 1600x1200.
Of course, it's too small on the desktop computer. I've set the sizes so that I could see the whole form on my notebook. But on the desktop computer, everything should be resized.
But on the large screen, things shouldn't be viewed bigger which means that the same amount of information can be displayed. Things should get a higher height and width value so that more information can be displayed.
In complicated code I mean something like this which should run automatically once when the form is created (OnCreate):
devResolutionX := 1280;
devResolutionY := 800;
useResolutionX := 1600; // how to get / read out this property?
useResolutionY := 1200; // how to get / read out this property?
Form1.Height := Form1.Height+devResolutionY-useResolutionY;
Form1.Height := Form1.Width+devResolutionX-useResolutionX;
// do that with all components which makes this approach complicated
What must I work with to reach that goal?
- ScaleBy
- alignments
- anchors
Thank you very much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您只需将表单的 BorderStyle 属性设置为 bsSizeable 即可。这将允许用户根据自己的需要调整表单大小(或最大化)。
您还需要在这里使用锚点。如果您为表单上的所有组件设置 akLeft、akTop、akRight 和 akBottom 锚点,它们将随表单调整大小。
然而,一旦你这样做了,你可能很快就会意识到这实际上并不是你想做的。这些不断增长的组成部分可能会相互重叠。因此,您需要考虑哪些组件的哪些边缘被锚定,哪些没有。
有时,您需要进行一些比单独锚点处理更复杂的组件移动和尺寸调整。在这些情况下,您将需要处理表单的 OnResize 事件。每当用户调整表单大小时都会触发此事件,并且您将有机会进行一些数学运算来重新计算某些组件的大小和位置。
It looks like you just need to set the BorderStyle property of your form to bsSizeable. This will allow the user to resize the form (or maximize it) as he sees fit.
You will also want to make use of anchors here. If you set the akLeft, akTop, akRight, and akBottom anchors for all the components on your form, they will resize with the form.
As soon as you do this, though, you will probably quickly realize that wasn't actually what you wanted to do after all. These growing components are probably going to overlap with each other. So, you are going to need to put some thought into which edges of which components get anchored and which don't.
Sometimes you will need to do some more complicated component moving and sizing than can be handled by anchors alone. In these cases, you will want to handle the Form's OnResize event. This event will get fired whenever the user resizes the form, and it will give you the chance to do some math to recalulate the sizes and positions of certain components.
只需正确设置锚点,就会显示附加信息。我不建议以编程方式强制任意高度和宽度。最好的办法是使用窗体的 OnClose 事件保存窗体的高度和宽度,然后使用 OnCreate 设置高度和宽度。
Just set your anchors correctly and the additional info will show. I wouldn't recommend programmatically forcing an arbitrary height and width. The best thing to do is use the form's OnClose event to save the form's height and width and then set the height and width with OnCreate.