Click here to Skip to main content
6,291,722 members and growing! (15,714 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate

Scrollable and RatioStretch PictureBox

By Gil Klod

A scrollable and ratio-stretch picture box control
C#, Windows, .NET 1.0, .NET 1.1, Dev
Posted:26 Apr 2003
Views:89,623
Bookmarked:28 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
29 votes for this article.
Popularity: 5.68 Rating: 3.88 out of 5
4 votes, 13.8%
1

2

3
6 votes, 20.7%
4
19 votes, 65.5%
5

Introduction

The Visual Studio.NET PictureBox control supports four behaviors of SizeMode property: Normal, StretchImage, AutoSize and CenterImage.

When I needed to use the PictureBox control it lacked two behaviors :

  1. Scrollable - The ability to use the scroll bars in order to view different areas of large image.
  2. RatioStretch - The ability to view stretched image in the same ratio (width / height) of the original image and avoids distortion of the stretched image.

The Viewer control which is available with this article supports the above two behaviors.

Note : This control supports scrolling using the mouse wheel.

Using the code

In order to use the Scrollable and RatioStretch capabilities of the Viewer control, simply add the Viewer control to your project and use it as follows :

    // open an image

    this.viewer1.Image = Image.FromFile(ImageFilepath);
    // set mode as Scrollable

    this.viewer1.ImageSizeMode = SizeMode.Scrollable;

In the sample above, we first load the image from the file specified by ImageFilepath, to the Viewer control. We then set its ImageSizeMode property to Scrollable, so that when the size of the image is greater than the visible area of the Viewer control, scrollbar(s) are added. Now, if we want the image to be displayed to fit within the Viewer control, without affecting the aspect ratio, we set the ImageSizeMode property of the Viewer control to RatioStretch as shown below:

    // set mode as RatioStretch

    this.viewer1.ImageSizeMode = SizeMode.RatioStretch;

That's all.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Gil Klod


Member

Location: Israel Israel

Other popular Miscellaneous articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 25 (Total in Forum: 25) (Refresh)FirstPrevNext
Generalbest no no Pinmemberkreont13:36 21 Dec '08  
Generallatest version Pinmemberalhambra-eidos2:21 1 Aug '08  
Generalhow to make Size long not int Pinmembermaimosa4:04 6 Aug '06  
Questionmanipulate scrollbar value by code PinmemberDaniel Junglen10:13 20 Jun '06  
Generalgood Pinmemberjinzhecheng21:13 7 Apr '06  
Generalexcellent.. no flicker! PinmemberTim_Mackey2:24 17 Aug '05  
GeneralRe: excellent.. no flicker! Pinmembergeahaad8:46 8 May '06  
Generalscrollable and ratiostrech picture Box in Visual FoxPro PinmemberBaba Kh.9:32 16 Apr '05  
GeneralMouseMove PinmemberDerPumuckl4:22 5 Apr '05  
GeneralRe: MouseMove Pinmemberachoi65:50 8 Apr '05  
GeneralRe: You can add an event.. :) PinmemberNicejinux1:21 31 Mar '09  
GeneralProblem adding DTC to toolbox... Pinmemberrcwatson7:19 10 Mar '05  
GeneralEvents Pinmemberachoi69:28 24 Feb '05  
GeneralWon't this be slow PinmemberMike Gore3:28 31 Mar '04  
Generalproblems with using design vew and this control? Pinmemberdazinith6:14 29 Apr '03  
GeneralRe: problems with using design vew and this control? PinmemberGil Klod7:34 29 Apr '03  
GeneralRe: problems with using design vew and this control? Pinmemberdazinith9:33 29 Apr '03  
GeneralAdding custom controls to the toolbox Pinmemberdrewnoakes3:02 28 Aug '03  
GeneralWhat about using a Panel? PinmemberMarc Clifton11:32 27 Apr '03  
GeneralRe: What about using a Panel? Pinmemberdazinith9:51 6 May '03  
GeneralRe: What about using a Panel? PinmemberMarc Clifton14:23 6 May '03  
GeneralRe: What about using a Panel? Pinmembergabis1:49 6 Aug '03  
GeneralRe: What about using a Panel? PinmemberVertexwahn4:53 22 Aug '05  
QuestionRe: What about using a Panel? PinmemberDr Reedo1:30 1 Feb '06  
AnswerRe: What about using a Panel? PinmemberDr Reedo1:40 1 Feb '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 26 Apr 2003
Editor: Nishant Sivakumar
Copyright 2003 by Gil Klod
Everything else Copyright © CodeProject, 1999-2009
Web19 | Advertise on the Code Project