2015年6月2日 星期二

[Microsoft Visual Basic 2010 Express]物件縮放

開發環境:Microsoft Visual Basic 2010 Express
原        理:利用比例關係進行物件的大小縮放,以免放大到全螢幕時物件會有比例不合
     問題


Public Class Form1

    Private Sub Form1_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated

        Dim oldH As Double = Me.Height
        Dim oldW As Double = Me.Width

        Me.WindowState = FormWindowState.Maximized

        Dim divH As Double
        Dim divW As Double
        Dim divF As Double

        Dim fs As FontStyle
        Dim fm As FontFamily
        Dim f As Font
        Dim fsize As Single

        divH = Me.Height / oldH
        divW = Me.Width / oldW

        If divH > divW Then
            divF = divW
        Else
            divF = divH
        End If

        For Each myObj In Me.Controls

            ' *=意思 myObj.Height = myObj.Height * divH

            myObj.Height *= divH
            myObj.Width *= divW
            myObj.Top *= divH
            myObj.Left *= divW

            fs = myObj.Font.Style
            fm = myObj.Font.FontFamily
            fsize = myObj.Font.Size * divF
            f = New Font(fm, fsize, fs)
            myObj.font = f

        Next

    End Sub

End Class

沒有留言:

張貼留言