delphi中如何设置窗体的宽度和高度
Delphi 7 中如何设置窗体的宽度和高度?该窗体上包含不同类型的控件。我需要将主窗体大小设置为 127x263。它应该以编程方式更改 单击按钮即可。
How can I set the width and height of a form in Delphi 7? The form contains different types of controls on it. I need to set the main form size to 127x263. It should change programmatically
in a button click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样:
或者您可能希望将客户区域设置为这些尺寸:
当然,您最常见的是在设计时在对象检查器中设置这些属性,然后将它们写入表单的 .dfm 文件中。
如果您希望在按钮单击上发生此类更改,请为按钮单击添加一个处理程序,如下所示:
在最后的摘录中,您不需要指定
MainForm
对象实例,因为事件处理程序是TMainForm
类的成员,因此Self
是隐式的。如果您希望遵循 Ulrich Gerhardt 的建议(请参阅评论)并使用
SetBounds
那么您可以这样写:最后,如果您的表单有
Scaled = True
那么您需要处理字体缩放。像这样的硬编码像素尺寸不适用于字体缩放设置为与您的机器不同的值的机器。Like so:
Or perhaps you want to set the client area to those dimensions:
Of course, you most commonly set these properties in the Object Inspector at design time and then they are written to your form's .dfm file.
If you want such a change to occur on a button click add a handler for the button click that looks like this:
In this last excerpt you don't need to specify the
MainForm
object instance because the event handler is a member of theTMainForm
class and so theSelf
is implicit.If you wish to follow Ulrich Gerhardt's advice (see comment) and use
SetBounds
then you would write:Finally, if your form has
Scaled = True
then you need to deal with font scaling. Hard coded pixel dimensions like this will not be appropriate for machines with font scaling set to a different value from your machine.