
Introduction
Today's topic is about how to add ScrollBar
(s) into your PictureBox
controller to make surfing it easier and better.
Why ?
Well, if you want to open a picture with a big size (example: 1920 x 1200) and your screen's resolution in ways smaller than that, then you will be obligated to resize or zoom it, other words: you will edit it.
Zooming or changing the size of a picture may distort it, so I suggest you to use scroll bars to make the view look better .
How to Add the Scrollbar
-
Add a Panel Controller

-
Click on it
-
Go to the properties
-
Select (AutoScroll) and change it from false to true

-
Add a PictureBox (here like the picture shows)

-
Go to the properties of the PictureBox, select SizeMode property and change it to (AutoSize)

That's it!
Using the Code
There isn't a lot of code in this topic, it is all related to the designer.
The only two code's methods I will post here are:
- Check if the picture exists or not.
- If it is does exist, then it will import it and show it into the
PictureBox
.
Check the Existence
if (System.IO.File.Exists(path))
{
}
else
{
}
Import the Picture
Pic.Image = Image.FromFile(path);
Final Code
if (System.IO.File.Exists(path))
{
Pic.Image = Image.FromFile(path);
}
else
{
}
Notice
The code and the project are too simple, i just posted it to show a trick to add ScrollBar
to the PictureBox
controller .