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

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

 

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

上一篇:WinForm只能运行一个实例,存在则激活


下一篇:loadrunner webhttp protocol中一些常用js api