VB6 中的窗体居中

发布于 2024-08-21 22:08:26 字数 77 浏览 8 评论 0原文

我正在编写一个在我们公司内部使用的程序,并遇到了以下问题:

当使用 MDI 父最大化窗体作为背景时,如何使子窗体在屏幕上居中

I am writing a programme to be used internaly within our company and have come across the problem below:

How can you get a Child form to centre on the screen when using the MDI parent maximised form as the backgroung

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

女中豪杰 2024-08-28 22:08:26

在 MDI 子屏幕中,创建一个 Form_Initialize 函数,如下所示:

Private Sub Form_Initialize()

    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2

End Sub

当然,您需要替换上面代码中看到的 MDIForm1 的 MDI 表单名称。

In the MDI child screen, create a Form_Initialize function like this:

Private Sub Form_Initialize()

    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2

End Sub

Of course, you'll need to substitute the name of your MDI form where you see MDIForm1 in the code above.

街道布景 2024-08-28 22:08:26

来自微软:
“MDI 子窗体的初始大小和位置由 Microsoft Windows 操作环境控制,除非您在 Load 事件过程中专门设置它们。”

来自父母:

Private Sub MDIForm_Load()
    CenterChildForm MDIForm1, Form1
End Sub

Sub CenterChildForm(Parent As Form, Child As Form)
     If Parent.WindowState = 1 Then Exit Sub 'The Parent is minimized, centering is invalid.

     Child.Top = (Parent.ScaleHeight - Child.Height) / 2
     Child.Left = (Parent.ScaleWidth - Child.Width) / 2
End Sub

来自孩子:

Private Sub Form_Load()
    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub

From Microsoft:
"The initial size and placement of MDI child forms are controlled by the Microsoft Windows operating environment unless you specifically set them in the Load event procedure."

From the parent:

Private Sub MDIForm_Load()
    CenterChildForm MDIForm1, Form1
End Sub

Sub CenterChildForm(Parent As Form, Child As Form)
     If Parent.WindowState = 1 Then Exit Sub 'The Parent is minimized, centering is invalid.

     Child.Top = (Parent.ScaleHeight - Child.Height) / 2
     Child.Left = (Parent.ScaleWidth - Child.Width) / 2
End Sub

From the Child:

Private Sub Form_Load()
    Me.Left = (MDIForm1.ScaleWidth - Me.Width) / 2
    Me.Top = (MDIForm1.ScaleHeight - Me.Height) / 2
End Sub
时光是把杀猪刀 2024-08-28 22:08:26

从 IDE 右下角的属性中选择 WINDOWS PROPERTY - CENTER PARENT。它的命名可能有点不同,但在下拉菜单中带有中心屏幕

编辑:我认为它是 WINDOWS POSITION - CENTER PARENT

Select from the properties in the IDE on the bottom right the WINDOWS PROPERTY - CENTER PARENT. It may be named something a little difference but is in the drop down with CENTER SCREEN

EDIT: I think it is WINDOWS POSITION - CENTER PARENT

℉服软 2024-08-28 22:08:26

作为上述方法的补充,使用 me.Move [left]、[top]、[width]、[height] 方法,

它更快,并且在单个操作中执行定位。

As an addition to the above use the me.Move [left], [top], [width], [height] method

it is quicker and performs the positioning in a single action.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文