VB.Net 窗体居中显示(1)

时间:2021-05-18 12:26:03   收藏:0   阅读:15

Form窗体有一个属性是StartPosition,把它设置为CenterScreen就是居中。
代码为 Me.StartPosition = FormStartPosition.CenterScreen。

如果是非要计算分辨率的话:
My.Computer.Screen.Bounds.Width 是分辨率中的宽度
My.Computer.Screen.Bounds.Height 是分辨率中的高度
那么
Me.Top = (My.Computer.Screen.Bounds.Height - Me.Height) / 2
Me.Left = (My.Computer.Screen.Bounds.Width - Me.Width) / 2
就是让窗体居中啦~

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

        Me.Top = (My.Computer.Screen.Bounds.Height - Me.Height) / 2
        Me.Left = (My.Computer.Screen.Bounds.Width - Me.Width) / 2

        Me.StartPosition = FormStartPosition.CenterScreen

        Me.Left = 0 : Me.Top = 0
        Me.Width = My.Computer.Screen.Bounds.Width  ‘是分辨率中的宽度
        Me.Height = My.Computer.Screen.Bounds.Height ‘是分辨率中的高度

    End Sub
End Class

 

原文:https://www.cnblogs.com/mydoor/p/14779687.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!