I show a JPEG in a Canvas. The Canvas resizes with the window. The JPEG has its fixed ratio (height/width). How do I prevent the user from enlarging the window beyond the ratio of the JPEG?
Try the “Resizing” event of the window, and either set the window width to match the new height or vice versa. You may want to keep track of the size before resizing starts. Copy width/height to a property in Open and Resized. This could help you get better tracking logic so you can figure out whether the user’s resize intent is primarily horizontal or vertical or neither.
No, I have tried that endlessly…
The Canvas has a Pic1 as Picture property and contains this code in the Paint event:
[code] If Pic1<> Nil then
Dim scale As Double
scale = Min( g.Width / me.Pic1.Width, g.Height / me.Pic1.Height )
g.DrawPicture( me.Pic1 , 0, 0, scale * me.Pic1.Width, scale * me.Pic1.Height, 0, 0, me.Pic1.Width, me.Pic1.Height )
Have you set the canvas locking to left, top, right, and bottom, so that it conforms to the window?
Let’s assume your window is 40 pixel wider than the canvas in this window (and the canvas is set to the size of your picture)
Put this code into the Resizing Event Handler of the Window and your problem should be solved.
If Me.width>Canvas1.Width+40 then Me.width=Canvas1.Width+40
If Me.Height>Canvas1.Height+40 then Me.width=Canvas1.Height+40
Mmmm… Better, but stil I have this right side void. The window sticks close to the canvas but with this say 100 pixel empty space, which stays proportional with scaling the window…
Change the canvas and window width to match the scaled image.