Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2006

Tip: Looking for answers? Try searching our database.

Preserve Aspect Ratio When Resizing Form

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marcus Kwok - 19 Apr 2006 21:53 GMT
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++.

Thanks for any advice.

Signature

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

larrylard@hotmail.com - 20 Apr 2006 17:34 GMT
> 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,
[quoted text clipped - 9 lines]
> 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/frlrfSystemWindowsFormsContro
lClassResizeTopic.asp
>

should point you in the right direction.

Signature

Larry Lard
Replies to group please

Marcus Kwok - 25 Apr 2006 17:24 GMT
>> 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,
[quoted text clipped - 17 lines]
>
> 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.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.