怎样使窗体浮现在屏幕的中央?

解决方案 »

  1.   

    '*********************************************************
    '* 名称:FormSet(formname,mode)
    '* 功能:此函数用于初始化窗体的大小和位置
    '* 用法:mode 满屏(0),左上(1),右上(2),左下(3),右下(4),居中(5)
    '*********************************************************
    Public Function FormSet(F As Form, Nu As Integer) As String
        Dim BarHeight As Integer  '任务条的高度
        BarHeight = 27 * 15
        If IsNull(Nu) Then
            Nu = 0
        End If
        F.ScaleMode = 3 '将窗体的分辨率设为象素级
        Select Case Nu  '根据参数设置窗体的大小和位置
            Case 0          '默认的窗体效果,最大化
                With F
                    .top = 0
                    .Left = 0
                    .Width = Screen.Width
                    .Height = Screen.Height - BarHeight
                End With
            Case 1          '窗体的位置居左上
                With F
                    .top = 0
                    .Left = 0
                End With
            Case 2          '窗体的位置居右上
                With F
                    .top = 0
                    .Left = Screen.Width - .Width
                End With
            Case 3          '窗体的位置居左下
                With F
                    .top = Screen.Height - .Height - BarHeight
                    .Left = 0
                End With
            Case 4          '窗体的位置居右下
                With F
                    .top = Screen.Height - .Height - BarHeight
                    .Left = Screen.Width - .Width
                End With
            Case 5          '窗体的位置居中
                With F
                    .top = (Screen.Height - .Height) / 2
                    .Left = (Screen.Width - .Width) / 2
                End With
        End Select
        F.Icon = F_Main.Icon
    End Function
      

  2.   

    Private Sub Form_Load()
    Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
    End Sub