0

我正在尝试为我的表单按比例调整大小,所以我需要知道每次调整大小,究竟是什么调整了 - 宽度、高度或两者兼而有之。如何从System.EventArgs参数中获取该信息?

4

1 回答 1

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
于 2012-10-27T19:51:24.157 回答