1

enter image description hereI am trying to resize a red rectangle (via a class who inherit PictureBox) in a PictureBox containing an Image, but I have few issues with the method OnResize. I can resize this frame only with the corner bottom-right, which keep the ratio of the frame to 1.5 (landscape). But, when I am resizing the red rectangle, the resizing action should stop when it touch the right or bottom side, but it is working only partially: stop on the right side, but carry on on the bottom side (see pictures).

Below is the code of the OnResize method, but to fully understand the problem, you can follow this Google Drive Link which will give you a short version/application of what I am doing with the issue.

Any ideas are obviously welcome, as there is something I don't understand.

Thanks,

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
4

2 に答える 2