您可以尝试使用Select语句:
Select Case Me.Height
Case 425 To 732
Me.Height = 424
Case 733 To 1079
Me.Height = 732
End Select
回答你的进一步问题。如果您要使用 Form Resize 事件,您拥有的任何动画都会变得有趣,因为当您更改 Form Height 时,它将重新触发事件。就个人而言,如果我是你,我会坚持你最初的想法,即捕捉到下一个高度,如果你想为表单高度设置动画,我会认真研究 WPF。但这里是我说过要展示给你看的 SubRoutine,我使用了三个按钮来启动调整大小。如果您不阻止该事件重新运行子例程,则将其放入表单调整大小事件中时要小心,它将冻结您的计算机。
Public Class Form1
Private Sub Form1_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
Me.Text = Me.Height
End Sub
Public Sub ChangeFormHeight(fromHeight As Integer, toHeight As Integer)
If fromHeight > toHeight Then
For newHeight As Integer = fromHeight To toHeight Step -1
Me.Height = newHeight
Next
Else
For newHeight As Integer = fromHeight To toHeight
Me.Height = newHeight
Next
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ChangeFormHeight(Me.Height, 424)
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
ChangeFormHeight(Me.Height, 733)
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
ChangeFormHeight(Me.Height, 1080)
End Sub
End Class