Click here to Skip to main content
Licence 
First Posted 11 Apr 2005
Views 121,007
Bookmarked 58 times

PictureBox with zooming and scrolling

By | 11 Apr 2005 | Article
Article on creating a user defined PictureBox control.

Screenshot form PicturBoxCtrl testprogram

Introduction

In a past project, I designed a GUI with a PictureBox control on it. Because of the low screen resolution, I couldn't make the GUI big enough to show the whole picture. So I decided to develop my own scrollable PictureBox with the special highlight of zooming functionality. For that, I created a new VS project of type 'Windows control library'. In the source code, you can see the derived class.

How it works

When the mouse cursor enters the control, the cursor style changes and you are able to zoom in or out with the mouse-wheel. The principle of the zooming effect is to raise or to lower the inner PictureBox size by a fixed zooming factor. The scrollbars appear automatically when the inner PictureBox gets bigger than the control.

Using the control

The control resides in the namespace PictureBoxCtrl. There we have one public class PictureBox : System.Windows.Forms.UserControl.

The control provides two properties:

  • Picture - A string which represents the name of the picture. If an error occurs during load, the PictureBox shows a red cross. Supported file formats are: *.gif, *.tif, *.jpg, *.bmp.
  • Border - The same as the BorderStyle property in other controls.

Note: None of the properties have been added to the Appearance category in the property page of the control.

Bring the control to the Toolbox

  1. Compile the project PicturBoxCtrl.
  2. Go to the VS ToolBox.
  3. Create a tab (or use an existing one).
  4. Right click in the tab --> Add/Remove Items.

    Right-click in the toolbox

  5. Here you browse for the PictureBox.dll (in PictureBox\bin\Debug or PictureBox\bin\Release). Select it and press OK.

Browse for the .dll

Now you've rebound the control into the toolbox. From here, you can drop it to your form. The VS wizard will automatically add a reference for you to your project.

PicturBoxCtrl in the toolbox

That's it...

So, this is my first C# User Control. For my needs, the control is finished, maybe for yours too. If not, feel free to enhance the code.

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

Alexander Kloep

Software Developer
www.auteq.com
Germany Germany

Member

Working as software engineer since 2001 at www.auteq.com.
 
In my spare time i love playing with my two kids.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionhow save image in picturebox? PinmemberJheiron5:29 17 Oct '11  
AnswerRe: how save image in picturebox? PinmemberAlexander Kloep20:41 17 Oct '11  
GeneralRe: how save image in picturebox? PinmemberJheiron3:17 18 Oct '11  
GeneralRe: how save image in picturebox? PinmemberAlexander Kloep20:27 18 Oct '11  
GeneralRe: how save image in picturebox? PinmemberJheiron3:16 19 Oct '11  
GeneralMy vote of 5 PinmemberMr.YunJi7:04 31 Oct '10  
GeneralFile is being used by another process Pinmemberw, tim8:44 18 Jan '10  
GeneralRe: File is being used by another process PinmemberAlexander Kloep19:36 18 Jan '10  
GeneralImage is too small Pinmemberhuhuhujujuju3:13 9 Jan '10  
GeneralNice job PinmemberX3m8:45 26 Apr '08  
GeneralImage Zoomin and ZoomOut PinmemberMember 459512223:30 6 Feb '08  
GeneralImage Property PinmemberSteveConradEllis1:17 7 Sep '06  
GeneralRe: Image Property PinmemberCode Deamon1:33 19 Apr '07  
GeneralRe: Image Property PinmemberAl_S5:28 10 Mar '09  
GeneralDrag to scroll PinmemberMrQBerrt10:01 30 Sep '05  
GeneralRe: Drag to scroll PinmemberChristopher Scholten18:06 10 Nov '05  
NewsRe: Drag to scroll PinmemberChristopher Scholten20:10 10 Nov '05  
GeneralRe: Drag to scroll PinmemberSeishin#11:29 15 Sep '08  
GeneralSuggestion PinmemberNinjaCross2:33 14 Sep '05  
GeneralRe: Suggestion PinmemberAlexander Kloep19:43 14 Sep '05  
QuestionDisabled in ToolBox ? Pinmemberangel4208:40 19 Aug '05  
AnswerRe: Disabled in ToolBox ? Pinmemberangel42010:26 19 Aug '05  
GeneralControl PinsussAnonymous16:58 29 Jun '05  
GeneralRe: Control PinsussAnonymous19:54 29 Jun '05  
GeneralRe: Control PinsussAnonymous3:15 30 Jun '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120515.1 | Last Updated 12 Apr 2005
Article Copyright 2005 by Alexander Kloep
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid