首页 > Windows开发 > 详细

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

时间:2021-05-18 12:26:03      阅读:15      评论:0      收藏:0      [点我收藏+]

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)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!