Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scrolling Horitionally whil fitting photo's vertical edge to picturebox and panel respectively

Posted on 2007-03-25
1
Medium Priority
?
483 Views
Last Modified: 2007-03-27
Hi all,

I'd like to display a very long panorama in a c# form. The panorama is placed in a picturebox and the picturebox is placed inside a panel. I am not sure if there's way to fit picturebox's vertical edge (and at the same time picture's height are resize to fit the height of picturebox) to the panel (that means vertical scrollbar is not needed) while allows users to scroll horizontally.
0
Comment
Question by:alenwong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
kingtam2000 earned 1500 total points
ID: 18788944
While I believe there is no property that would allow you to stretch one direction but not the other, the following code should allow you to do what you wanted, either putting it in form_load (replacing pictureBox1 with the name of the picturebox and panel1 with the name of the panel) or putting the settings into the properties in form designer, apart from the calculated ones:

            //Set the location of the picture box to the top left corner of the panel or whereever in the panel that the picturebox should be set
            pictureBox1.Location = new Point(0, 0);
            //Set the height to be the height of the panel subtracting the height of the horizontal scroll bar, otherwise the horizontal scroll bar would block off part of the image
            pictureBox1.Height = panel1.Height - SystemInformation.HorizontalScrollBarHeight;
            //Set the picture box width to be the width of the image when stretched to that of the vertical so that the stretch remains the same of both the vertical and the horizontal.  If you only wanted the vertical axis to stretch then just set the width to be pictureBox1.Image.Size.Width
            pictureBox1.Width = (int) (pictureBox1.Image.Size.Width * ((double) pictureBox1.Height / (double) pictureBox1.Image.Size.Height));
            //Stretch the image so that all of the image would fit into the picture box
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            //AutoScroll to add the horizontal scroll bar if neccessary
            panel1.AutoScroll = true;

Hope that helps
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question