最大化时,如何使表单内的内容处于居中位置? [英] How to make the things inside a form to be in center position When maximised.?

查看:97
本文介绍了最大化时,如何使表单内的内容处于居中位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的编码员,

我知道我们可以通过更改表单属性的起始位置来使窗口显示在屏幕中央.但是我想知道一旦窗口最大化,我们如何使事物包含在表单的中心?请帮助.

Dear Coders,

I know that we can make the window to appear in the center of the screen by changing startposition from the form properties. But i would like to know once the window is maximized how do we make things to be contained in the center of the form? Please Help.

推荐答案

在表单设计器中,要与表单中心保持相对位置的控件上,只需将Anchor设置为None.
在一个窗体中,其所有控件的Anchor = None都将被调整,在调整窗体大小时,它将随着窗体在每一侧(上,下,左,右)的扩展而出现,所有初始控件都位于同一位置.
In the form designer, on the controls you want to keep at the same relative position to the center of the form, just set Anchor to None.
In a form, with all its controls with Anchor=None, when the form is resized, it will appear as the form is extended on every side (up, down, left, right) with all the initial controls at the same position at the center of the form.


您可以获取主表单的宽度和高度以及要居中的对象的宽度和高度,然后将两者相减一并除以二.

You take the width and height of the mainform and the width and height of the object you want to centralise and subtract one from the other and divide by two.

Sub Centralise(CenterThis as object, InThisForm as object)
  CenterThis.left = (InThisForm.Width - CenterThis.Width) / 2
  CenterThis.top = (InThisForm.Height - CenterThis.Height) / 2
End Sub


这篇关于最大化时,如何使表单内的内容处于居中位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆