Re: Preserve Aspect Ratio When Resizing Form

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



larrylard@xxxxxxxxxxx wrote:

Marcus Kwok wrote:
I have a Form that has a PictureBox in it that has a dock style set to
"fill". I can set the PictureBox's PictureBoxSizeMode to StretchImage,
but I would like to preserve the aspect ratio of the image so that the
user may scale the size of the image but not squish it out of
proportion. Is there a simple way to do this?

If it is not possible or requires too much overhead I may just use the
ScrollablePictureBox from
http://www.c-sharpcorner.com/Graphics/ScrollablePictureBox.asp
and forget about being able to resize the image.

I am writing in Managed C++ (.NET 1.1) but in the past I have not had
much difficulty translating code from VB.NET or C# into Managed C++.

The example code at

<http://tinyurl.com/mc9wn>
=
<http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsControlClassResizeTopic.asp>

should point you in the right direction.

Thanks for the link. Keeping the window square is easy and works.
However, I am having problems with my method:

I added a double to the class called aspect_ratio.

In the constructor, I calculate

aspect_ratio = static_cast<double>(image->Width) / static_cast<double>(image->Height);


Then in the Resize event handler:

System::Void PlotDisplayWindow_Resize(System::Object * sender, System::EventArgs * e)
{
Control* control = __try_cast<Control*>(sender);

// Looking at this, I think I need Height instead of Width, but the
// concept is what's important
control->Size = System::Drawing::Size(static_cast<int>(aspect_ratio * control->Size.Width), control->Size.Width);
}


When I do this and try to resize the form, I get a flickering of
rectangles of the appropriate aspect ratio as I drag the border of the
frame, but as soon as I let go of the border then the window snaps back
to its original size.

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
.



Relevant Pages

  • Re: resolution for printing?
    ... I'm currently cropping some images using the marquee and its fixed ... > 4 x 6 based on the ratio. ... If you are really unsure of print settings there is a wizard to resize the ...
    (comp.graphics.apps.photoshop)
  • Re: VB6 and Widescreen monitors
    ... from a standard ratio. ... Are you trying to resize or reposition any of the controls in the form? ... Why don't you describe what the form looks like on the screens where you like ... Surely you recognize that some forms, say Internet Explorer for example, display ...
    (comp.lang.basic.visual.misc)
  • Re: 4:3 games on 5:4 monitors - good or bad?
    ... to play older Windows 98 based rpgs. ... screen with a large black boarder rather then resize. ... to CRT type monitors. ... Also, besides letting the monitor handle the ratio, with nVidia (and I ...
    (comp.sys.ibm.pc.games.rpg)
  • Re: make lock aspect ratio the default on images Word 2007
    ... The "secret" is in how the file was spec'd when created - it isn't Word's ... into Word that its aspect ratio is not locked. ... Picture tab and entering a new value, ... group and select the Keep Aspect Ratio option before i can resize the ...
    (microsoft.public.word.drawing.graphics)