Click here to Skip to main content
15,352,915 members
Articles / Programming Languages / C#
Posted 26 Apr 2003


40 bookmarked

Scrollable and RatioStretch PictureBox

Rate me:
Please Sign up or sign in to vote.
4.69/5 (31 votes)
26 Apr 20031 min read
A scrollable and ratio-stretch picture box control

Image 1


The Visual Studio.NET PictureBox control supports four behaviors of

property: Normal, StretchImage,
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

Comments and Discussions

Questionbest way to strech Pin
GPSol15-Aug-15 11:56
MemberGPSol15-Aug-15 11:56 
GeneralMy vote of 5 Pin
Manoj Kumar Choubey1-Mar-12 22:52
professionalManoj Kumar Choubey1-Mar-12 22:52 
GeneralThank you Pin
huhuhujujuju9-Jan-10 11:10
Memberhuhuhujujuju9-Jan-10 11:10 
Generalbest no no Pin
kreont21-Dec-08 12:36
Memberkreont21-Dec-08 12:36 
Generallatest version Pin
kiquenet.com1-Aug-08 1:21
professionalkiquenet.com1-Aug-08 1:21 
Questionhow to make Size long not int Pin
maimosa6-Aug-06 3:04
Membermaimosa6-Aug-06 3:04 
hi there,
first of all thanks for your control,but i need to know how can i make the size of pictureBox to be Long type than to be integer type.
thx in advance,
Questionmanipulate scrollbar value by code Pin
Daniel Junglen20-Jun-06 9:13
MemberDaniel Junglen20-Jun-06 9:13 
Generalgood Pin
jinzhecheng7-Apr-06 20:13
Memberjinzhecheng7-Apr-06 20:13 
Generalexcellent.. no flicker! Pin
Tim_Mackey17-Aug-05 1:24
MemberTim_Mackey17-Aug-05 1:24 
GeneralRe: excellent.. no flicker! Pin
geahaad8-May-06 7:46
Membergeahaad8-May-06 7:46 
Generalscrollable and ratiostrech picture Box in Visual FoxPro Pin
Baba Kh.16-Apr-05 8:32
MemberBaba Kh.16-Apr-05 8:32 
GeneralMouseMove Pin
DerPumuckl5-Apr-05 3:22
MemberDerPumuckl5-Apr-05 3:22 
GeneralRe: MouseMove Pin
achoi68-Apr-05 4:50
Memberachoi68-Apr-05 4:50 
GeneralRe: You can add an event.. :) Pin
Nicejinux31-Mar-09 0:21
MemberNicejinux31-Mar-09 0:21 
GeneralProblem adding DTC to toolbox... Pin
rcwatson10-Mar-05 6:19
Memberrcwatson10-Mar-05 6:19 
GeneralEvents Pin
achoi624-Feb-05 8:28
Memberachoi624-Feb-05 8:28 
GeneralWon't this be slow Pin
Mike Gore31-Mar-04 2:28
MemberMike Gore31-Mar-04 2:28 
Questionproblems with using design vew and this control? Pin
dazinith29-Apr-03 5:14
Memberdazinith29-Apr-03 5:14 
AnswerRe: problems with using design vew and this control? Pin
Gil Klod29-Apr-03 6:34
MemberGil Klod29-Apr-03 6:34 
GeneralRe: problems with using design vew and this control? Pin
dazinith29-Apr-03 8:33
Memberdazinith29-Apr-03 8:33 
GeneralAdding custom controls to the toolbox Pin
Drew Noakes28-Aug-03 2:02
MemberDrew Noakes28-Aug-03 2:02 
QuestionWhat about using a Panel? Pin
Marc Clifton27-Apr-03 10:32
mvaMarc Clifton27-Apr-03 10:32 
AnswerRe: What about using a Panel? Pin
dazinith6-May-03 8:51
Memberdazinith6-May-03 8:51 
GeneralRe: What about using a Panel? Pin
Marc Clifton6-May-03 13:23
mvaMarc Clifton6-May-03 13:23 
GeneralRe: What about using a Panel? Pin
gabis6-Aug-03 0:49
Membergabis6-Aug-03 0: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.