Click here to Skip to main content
Click here to Skip to main content

PictureBox with zooming and scrolling

, 11 Apr 2005 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Alexander Kloep
Software Developer www.rowa.de
Germany Germany
Working as software engineer since 2001. I started with c, c++ came up to c# and wpf today.

Comments and Discussions

 
QuestionError : Object reference not set to an instance of an object. PinmemberThilak Kumar10-Dec-12 20:41 
QuestionError : Object reference not set to an instance of an object. PinmemberThilak Kumar10-Dec-12 20:40 
QuestionError : Object reference not set to an instance of an object. PinmemberThilak Kumar10-Dec-12 20:40 
QuestionObject reference not set to an instance of an object. PinmemberThilak Kumar10-Dec-12 20:40 
Questionhow save image in picturebox? PinmemberJheiron17-Oct-11 5:29 
AnswerRe: how save image in picturebox? PinmemberAlexander Kloep17-Oct-11 20:41 
GeneralRe: how save image in picturebox? PinmemberJheiron18-Oct-11 3:17 
GeneralRe: how save image in picturebox? PinmemberAlexander Kloep18-Oct-11 20:27 
GeneralRe: how save image in picturebox? PinmemberJheiron19-Oct-11 3:16 
GeneralMy vote of 5 PinmemberMr.YunJi31-Oct-10 7:04 
GeneralFile is being used by another process Pinmemberw, tim18-Jan-10 8:44 
GeneralRe: File is being used by another process PinmemberAlexander Kloep18-Jan-10 19:36 
GeneralImage is too small Pinmemberhuhuhujujuju9-Jan-10 3:13 
GeneralNice job PinmemberX3m26-Apr-08 8:45 
GeneralImage Zoomin and ZoomOut PinmemberMember 45951226-Feb-08 23:30 
GeneralImage Property PinmemberSteveConradEllis7-Sep-06 1:17 
GeneralRe: Image Property PinmemberCode Deamon19-Apr-07 1:33 
GeneralRe: Image Property PinmemberAl_S10-Mar-09 5:28 
GeneralDrag to scroll PinmemberMrQBerrt30-Sep-05 10:01 
GeneralRe: Drag to scroll PinmemberChristopher Scholten10-Nov-05 18:06 
NewsRe: Drag to scroll PinmemberChristopher Scholten10-Nov-05 20:10 
GeneralRe: Drag to scroll PinmemberSeishin#15-Sep-08 11:29 
GeneralSuggestion PinmemberNinjaCross14-Sep-05 2:33 
GeneralRe: Suggestion PinmemberAlexander Kloep14-Sep-05 19:43 
QuestionDisabled in ToolBox ? Pinmemberangel42019-Aug-05 8:40 

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.

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