Solved

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

Posted on 2007-03-25
1
477 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 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

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:…
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!
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

617 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