OnResize method not fully working in VB.net

Jean-Luc Coudret 21 Reputation points
2021-06-09T20:30:20.36+00:00

Hi,

I am trying to resize a frame (via a class who inherit PictureBox) in aPictureBox containig an Image, but I have few issues with the method OnResize.
1- I can move this frame (red rectangle) via OnMove method (no problem)
2- I can resize this frame only with the corner bottom-right, which keep the ratio of the frame to 1.5 (landscape) or 0.66 (Portrait)
3- When I am resizing the frame, the resizing action should stop when it touch the right or bottom side, but it is working only partially.
4- To see the issue you have to move the red frame close to the right side or the bottom side and then try to increase the frame.

I tried various code options, but I can't find the solution.
Below is the code of the OnResize method, but to fully understand the problem, you can follow this link (Google Drive) which will give you a short version/application of what I am doing with the issue.

Any ideas are obviously welcome.

Thanks,
JLuc

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
        ' To redraw the whole image based on Glass window
        Try
            ' Minimum limits of Glass window
            If Me.Width < 40 Then Me.Width = CInt(40 * Form1.dRatioImageWH)
            If Me.Height < 40 Then Me.Height = CInt(40 / 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
            If Form1.dRatioImageWH > 1 Then Me.Height = CInt(Me.Width / Form1.dRatioImageWH)
            If Form1.dRatioImageWH < 1 Then Me.Width = CInt(Me.Height * Form1.dRatioImageWH)
            ' Control to be redrawn
            Me.Invalidate()
            ' Raise the Resize event
            MyBase.OnResize(e)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,819 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.