Bonjour,
La procedure "OnResize" ci-dessous fait partie d'une Class qui inherits PictureBox, mais elle ne marche qu'en partie.
En bref, j'ai un rectangle rouge qui peut bouger (OnMove) sur une image et aussi s'aggrandir (OnResize) sur cette image en gardant certaines proportions.
Le probleme se situe sur la methode OnRezise. Cela peut marcher sur une image en Landscape (voir photos) ou en Portrait, mais seulement partiellement.
Dans le cas d'un Landscape, le OnResize s'arrete une fois arrivant sur le cote droit, mais continue a s'aggrandir sur le cote bas (voir photos jointes).
Dans le cas d'un Portrait, c'est l'inverse: cela s'arrete sur le bas, mais continue sur le cote droit.
Lorsque je regarde ce qui se passe avec ce code:
Form1.Label5.Text = CBool(Me.Height > Form1.PictureBox1.Height - Me.Location.Y).ToString
, ce boolean passe a TRUE, mais le rectangle rouge continue a s'aggrandir en dehors de l'image.
Je ne comprends plus rien. Toute idee est la bienvenue.
Si cela peut aider, je peux joindre tout le code d'une application simplifiee montrant le probleme.
Ou je peux joindre un lien de cette application (VS2019) sur Google Drive.
Merci,
Jean-Luc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
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 |
Partager