Click here to Skip to main content
12,398,816 members (59,907 online)
Click here to Skip to main content
Add your own
alternative version

Stats

180.3K views
17.5K downloads
64 bookmarked
Posted

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.

You may also be interested in...

Comments and Discussions

 
QuestionError : Object reference not set to an instance of an object. Pin
Thilak Kumar10-Dec-12 20:41
memberThilak Kumar10-Dec-12 20:41 
QuestionError : Object reference not set to an instance of an object. Pin
Thilak Kumar10-Dec-12 20:40
memberThilak Kumar10-Dec-12 20:40 
QuestionError : Object reference not set to an instance of an object. Pin
Thilak Kumar10-Dec-12 20:40
memberThilak Kumar10-Dec-12 20:40 
QuestionObject reference not set to an instance of an object. Pin
Thilak Kumar10-Dec-12 20:40
memberThilak Kumar10-Dec-12 20:40 
Questionhow save image in picturebox? Pin
Jheiron17-Oct-11 5:29
memberJheiron17-Oct-11 5:29 
AnswerRe: how save image in picturebox? Pin
Alexander Kloep17-Oct-11 20:41
memberAlexander Kloep17-Oct-11 20:41 
GeneralRe: how save image in picturebox? Pin
Jheiron18-Oct-11 3:17
memberJheiron18-Oct-11 3:17 
GeneralRe: how save image in picturebox? Pin
Alexander Kloep18-Oct-11 20:27
memberAlexander Kloep18-Oct-11 20:27 
GeneralRe: how save image in picturebox? Pin
Jheiron19-Oct-11 3:16
memberJheiron19-Oct-11 3:16 
GeneralMy vote of 5 Pin
Mr.YunJi31-Oct-10 7:04
memberMr.YunJi31-Oct-10 7:04 
GeneralFile is being used by another process Pin
w, tim18-Jan-10 8:44
memberw, tim18-Jan-10 8:44 
GeneralRe: File is being used by another process Pin
Alexander Kloep18-Jan-10 19:36
memberAlexander Kloep18-Jan-10 19:36 
GeneralImage is too small Pin
huhuhujujuju9-Jan-10 3:13
memberhuhuhujujuju9-Jan-10 3:13 
GeneralNice job Pin
X3m26-Apr-08 8:45
memberX3m26-Apr-08 8:45 
GeneralImage Zoomin and ZoomOut Pin
Member 45951226-Feb-08 23:30
memberMember 45951226-Feb-08 23:30 
GeneralImage Property Pin
SteveConradEllis7-Sep-06 1:17
memberSteveConradEllis7-Sep-06 1:17 
GeneralRe: Image Property Pin
Code Deamon19-Apr-07 1:33
memberCode Deamon19-Apr-07 1:33 
GeneralRe: Image Property Pin
Al_S10-Mar-09 5:28
memberAl_S10-Mar-09 5:28 
GeneralDrag to scroll Pin
MrQBerrt30-Sep-05 10:01
memberMrQBerrt30-Sep-05 10:01 
GeneralRe: Drag to scroll Pin
Christopher Scholten10-Nov-05 18:06
memberChristopher Scholten10-Nov-05 18:06 
NewsRe: Drag to scroll Pin
Christopher Scholten10-Nov-05 20:10
memberChristopher Scholten10-Nov-05 20:10 
GeneralRe: Drag to scroll Pin
Seishin#15-Sep-08 11:29
memberSeishin#15-Sep-08 11:29 
GeneralSuggestion Pin
NinjaCross14-Sep-05 2:33
memberNinjaCross14-Sep-05 2:33 
GeneralRe: Suggestion Pin
Alexander Kloep14-Sep-05 19:43
memberAlexander Kloep14-Sep-05 19:43 
QuestionDisabled in ToolBox ? Pin
angel42019-Aug-05 8:40
memberangel42019-Aug-05 8:40 
AnswerRe: Disabled in ToolBox ? Pin
angel42019-Aug-05 10:26
memberangel42019-Aug-05 10:26 
GeneralControl Pin
Anonymous29-Jun-05 16:58
sussAnonymous29-Jun-05 16:58 
GeneralRe: Control Pin
Anonymous29-Jun-05 19:54
sussAnonymous29-Jun-05 19:54 
GeneralRe: Control Pin
Anonymous30-Jun-05 3:15
sussAnonymous30-Jun-05 3:15 
Generalmetalkills is selling a component Pin
fferdinanvi11-Jun-05 12:11
memberfferdinanvi11-Jun-05 12:11 
GeneralA couple thoughts Pin
Marc Clifton12-Apr-05 1:32
protectorMarc Clifton12-Apr-05 1:32 

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
Web02 | 2.8.160721.1 | Last Updated 12 Apr 2005
Article Copyright 2005 by Alexander Kloep
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid