2012-10-27 76 views

回答

1

對於表單上子控件的大小調整,您應該更好地使用稱爲TableLayoutPanel的本機.NET控件 - 這樣可以避免大量手動編碼。否則,您可以使用Me.Size並寫下如下內容:

Dim _oldSize As Size 
Dim _allowScaling As Boolean = False 

Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
    '[...] perform initial setup of your controls 
    _oldSize = Me.Size 
    _allowScaling = True 
End Sub 

Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize 
    If Not _allowScaling Then Exit Sub 

    Dim deltaSize As Size = Me.Size - _oldSize 
    Dim deltaWidth As Integer = Math.Abs(deltaSize.Width) 
    Dim deltaHeight As Integer = Math.Abs(deltaSize.Height) 

    If deltaWidth > 0 And deltaHeight > 0 Then 
    'both width and height have changed 
    ElseIf deltaWidth > 0 Then 
    'width has changed 
    ElseIf deltaHeight > 0 Then 
    'height has changed 
    End If 

    _oldSize = Me.Size 
End Sub 
相關問題