Resize window keep proportion

how can i keep the proportions -> width:height of a window on a window resizing-event?


Compute the scale factor (use actual width and target width) and apply that value to Window1.Width and Window1.Height.

i did but get an stack overflow exception

[code]dim w,h,wtarget,htarget as Double
dim factor as Double = w/h


Strange… I use that trick to resize images and draw them in Canvas…

I try and come back.

You do not tell where (in which event) you execute the code…

Do you do that in the Resized Event ?

in window.resizing-event because it should proportionally live resize

That’s it: I moved it in a pushbutton and it works fine.

Now, the questio is: why do you apply a code resize in the user’s back ?
In other words, what your interface is that needs that kind of resize ?

There may be a different way to achieve that goal, maybe.

How many times a second this event is fired ?
(no, it’s a rethorical question only).

[quote=436468:@Marco Winster]window1.Width=wtarget

I’d not recommend to do this in the Resizing Event :wink:

Nor Resized Event, thus my test in a PushButton, then the question about why wanting to do so.

as i wrote, live resize a window proportionally… :wink:

Yes, I understand that, but what is your motivation to do that; why the window size have to be changed after the user does it ?

Do you have a Canvas with an image that have to be resized proportionally ?

I may not be clear enough:

doing a code resize while the window is resizing resized generate the stack overflow exception. So, uness using a timer / a thread / something to delegate the moment to execute the code, you will always get a stack overflow exception.

no, there is a custom movie player on it and i don’t want black bars so it has to resize proportionally…

If you do your code in the Resizing event, this will trigger a new Resizing event. Therefore, you get the StackOverflow. Try to move your code into the Resized event. Or manage your Resizing event with a boolean property.

Yes !

Apply the resize there and make to window resize using the MoviePlayer Width/Height.

Sorry not clear, but I hope you understand what I mean.

Same trouble there.

its that simple (0.666 is the ratio window height / window width)

dim w as integer=self.Width self.Height=w*0.666

works fine in resizing-event!