Solved

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

Posted on 2007-03-25
1
460 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
1 Comment
 
LVL 3

Accepted Solution

by:
kingtam2000 earned 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now