我正在尝试为我的表单进行按比例调整大小,所以我需要知道每个调整大小,究竟是什么调整大小 - 宽度,高度或两者。如何从System.EventArgs
参数中获取该信息?
答案 0 :(得分: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