0
我想爲我的表單做一個比例調整大小,所以我需要知道每個調整大小,調整大小 - 寬度,高度或兩者。我如何從System.EventArgs
參數中獲取這些信息?確定寬度或高度或兩者在調整大小時是否更改?
我想爲我的表單做一個比例調整大小,所以我需要知道每個調整大小,調整大小 - 寬度,高度或兩者。我如何從System.EventArgs
參數中獲取這些信息?確定寬度或高度或兩者在調整大小時是否更改?
對於表單上子控件的大小調整,您應該更好地使用稱爲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
您將其從Me.Size中取出。舊的大小是此屬性的以前的值,只是存儲它。 –