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
- Compile the project PicturBoxCtrl.
- Go to the VS ToolBox.
- Create a tab (or use an existing one).
- Right click in the tab --> Add/Remove Items.
- Here you browse for the PictureBox.dll (in PictureBox\bin\Debug or PictureBox\bin\Release). Select it and press OK.
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.
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.