Click here to Skip to main content
11,931,104 members (60,701 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked

Scrollable and RatioStretch PictureBox

, 26 Apr 2003
Rate this:
Please Sign up or sign in to vote.
A scrollable and ratio-stretch picture box control


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.


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
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

Questionbest way to strech Pin
Member 1119391115-Aug-15 12:56
memberMember 1119391115-Aug-15 12:56 
GeneralMy vote of 5 Pin
manoj kumar choubey1-Mar-12 23:52
membermanoj kumar choubey1-Mar-12 23:52 
GeneralThank you Pin
huhuhujujuju9-Jan-10 12:10
memberhuhuhujujuju9-Jan-10 12:10 
Generalbest no no Pin
kreont21-Dec-08 13:36
memberkreont21-Dec-08 13:36 
Generallatest version Pin
alhambra-eidos1-Aug-08 2:21
memberalhambra-eidos1-Aug-08 2:21 
Questionhow to make Size long not int Pin
maimosa6-Aug-06 4:04
membermaimosa6-Aug-06 4:04 
Questionmanipulate scrollbar value by code Pin
Daniel Junglen20-Jun-06 10:13
memberDaniel Junglen20-Jun-06 10:13 
Generalgood Pin
jinzhecheng7-Apr-06 21:13
memberjinzhecheng7-Apr-06 21:13 
Generalexcellent.. no flicker! Pin
Tim_Mackey17-Aug-05 2:24
memberTim_Mackey17-Aug-05 2:24 
GeneralRe: excellent.. no flicker! Pin
geahaad8-May-06 8:46
membergeahaad8-May-06 8:46 
Generalscrollable and ratiostrech picture Box in Visual FoxPro Pin
Baba Kh.16-Apr-05 9:32
memberBaba Kh.16-Apr-05 9:32 
GeneralMouseMove Pin
DerPumuckl5-Apr-05 4:22
memberDerPumuckl5-Apr-05 4:22 
GeneralRe: MouseMove Pin
achoi68-Apr-05 5:50
memberachoi68-Apr-05 5:50 
GeneralRe: You can add an event.. :) Pin
Nicejinux31-Mar-09 1:21
memberNicejinux31-Mar-09 1:21 
GeneralProblem adding DTC to toolbox... Pin
rcwatson10-Mar-05 7:19
memberrcwatson10-Mar-05 7:19 
GeneralEvents Pin
achoi624-Feb-05 9:28
memberachoi624-Feb-05 9:28 
GeneralWon't this be slow Pin
Mike Gore31-Mar-04 3:28
memberMike Gore31-Mar-04 3:28 
Questionproblems with using design vew and this control? Pin
dazinith29-Apr-03 6:14
memberdazinith29-Apr-03 6:14 
AnswerRe: problems with using design vew and this control? Pin
Gil Klod29-Apr-03 7:34
memberGil Klod29-Apr-03 7:34 
GeneralRe: problems with using design vew and this control? Pin
dazinith29-Apr-03 9:33
memberdazinith29-Apr-03 9:33 
GeneralAdding custom controls to the toolbox Pin
drewnoakes28-Aug-03 3:02
memberdrewnoakes28-Aug-03 3:02 
QuestionWhat about using a Panel? Pin
Marc Clifton27-Apr-03 11:32
memberMarc Clifton27-Apr-03 11:32 
AnswerRe: What about using a Panel? Pin
dazinith6-May-03 9:51
memberdazinith6-May-03 9:51 
GeneralRe: What about using a Panel? Pin
Marc Clifton6-May-03 14:23
memberMarc Clifton6-May-03 14:23 
GeneralRe: What about using a Panel? Pin
gabis6-Aug-03 1:49
membergabis6-Aug-03 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 27 Apr 2003
Article Copyright 2003 by Gil Klod
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid