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
Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Function after success of Jquery/AJAX action 9 28
parsing JSON help 1 20
JSON Deserialize issue 6 26
IEnumerable<T> to a List<T> 8 37
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

839 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