Private _resizeBegin As Boolean
Private _sizeChanged As Boolean
Private Sub Form1_ResizeBegin(sender As Object, e As EventArgs) Handles MyBase.ResizeBegin
_resizeBegin = True
End Sub
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles MyBase.SizeChanged
' This is to avoid registering this as a resize event if it was triggered
' by another action (e.g., when the form is first initialized).
If Not _resizeBegin Then Exit Sub
_sizeChanged = True
End Sub
Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles MyBase.ResizeEnd
_resizeBegin = False
If _sizeChanged Then
_sizeChanged = False
MessageBox.Show("The form has been resized.")
End If
End Sub
1条答案
按热度按时间kupeojn61#
为什么窗体移动会触发ResizeEnd?
因为这是文档中记录的行为。
ResizeEnd事件也会在使用者移动表单之后产生,通常是在标题列上按一下并拖曳。
如果希望在移动窗体时不触发某个事件,则应该使用
Resize
或SizeChanged
。这两个事件的问题是,* 当用户调整 * 窗体大小时,它们将被触发。要解决此问题,您可以将它与ResizeBegin
和ResizeEnd
一起使用,并在用户实际完成调整窗体大小时使用两个标志。下面是一个完整的示例:
需要注意的一点是,
ResizeBegin
和ResizeEnd
仅在用户 * 手动 * 调整 * 表单大小时触发。但是,它 * 不 * 处理其他情况,如通过代码调整表单大小、表单最大化或还原。