我正在尝试在包含图像的 PictureBox 中调整红色矩形(通过继承 PictureBox 的类)的大小,但 OnResize 方法几乎没有问题。我只能用右下角调整这个框架的大小,这样可以将框架的比例保持在 1.5(横向)。但是,当我调整红色矩形的大小时,调整大小的动作应该在它触及右侧或底部时停止,但它只是部分起作用:在右侧停止,但在底部继续(见图)。
下面是 OnResize 方法的代码,但要完全理解问题,您可以按照此Google Drive Link操作,它会为您提供我正在处理的问题的简短版本/应用程序。
显然欢迎任何想法,因为有些东西我不明白。
谢谢,
JLuc
Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
Try
' Minimum limits
If Me.Width < 40 Then Me.Width = CInt(40 * Form1.dRatioImageWH)
If Me.Height < 40 Then Me.Height = CInt(40 / Form1.dRatioImageWH)
' Keeping the ratio Width/Height = 1.5 (Landscape)
If Form1.dRatioImageWH > 1 Then Me.Height = CInt(Me.Width / Form1.dRatioImageWH)
' Effect on Resize event
If Me.Width > Form1.PictureBox1.Width - Me.Location.X Then Me.Width = Form1.PictureBox1.Width - Me.Location.X
If Me.Height > Form1.PictureBox1.Height - Me.Location.Y Then Me.Height = Form1.PictureBox1.Height - Me.Location.Y
' Control to be redrawn
Me.Invalidate()
' Raise the Resize event
MyBase.OnResize(e)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub