Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

16 Experts available now in Live!

Get 1:1 Help Now