Zoom at PictureBox
I have a Picture box at dock in parent container . And I want to create a button that it can zoom the picture in the PictureBox and unzoom it !!! have anyone any idea or a tutorial that it could help me ?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 11:04 AM EST
private void trackBar1_Scroll(object sender, EventArgs e)
{
double zoomlevel = 1+ trackBar1.Value * 0.1;
ZoomIN(zoomlevel);
}
private void ZoomIN(double zoomLevel)
{
System.Drawing.Rectangle screenSize = new System.Drawing.Rectangle();
screenSize.Width = SystemInformation.VirtualScreen.Width;
screenSize.Height = SystemInformation.VirtualScreen.Height;
//int zoomFactor = 10;
Image img = pictureBox1.Image;
Bitmap bitMapImg = new Bitmap(img);
if (bitMapImg.Width < screenSize.Width && bitMapImg.Height < screenSize.Height)
{
Size newSize = new Size((int)(bitMapImg.Width * zoomLevel), (int)(bitMapImg.Height * zoomLevel));
Bitmap bmp = new Bitmap(bitMapImg, newSize);
pictureBox1.Image = (Image)bmp;
}
}
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 5:15 AM EST
private void btn_ZoomIN_Click(object sender, EventArgs e)
{
System.Drawing.Rectangle screenSize = new System.Drawing.Rectangle();
screenSize.Width = SystemInformation.VirtualScreen.Width;
screenSize.Height = SystemInformation.VirtualScreen.Height;
int zoomFactor = 10;
Image img = pictureBox1.Image;
Bitmap bitMapImg = new Bitmap(img);
if (bitMapImg.Width < screenSize.Width && bitMapImg.Height < screenSize.Height)
{
Size newSize = new Size((int)(bitMapImg.Width * zoomFactor), (int)(bitMapImg.Height * zoomFactor));
Bitmap bmp = new Bitmap(bitMapImg, newSize);
pictureBox1.Image = (Image)bmp;
}
}
Note: But to see zooming, you need to add scrollbar on your picture Box.
To get scroll bar on Picture Box:
Place your PictureBox into Panel.
Set 'SizeMode' property of PictureBox to "AutoSize"
Nikos Rak11 reputationPosted Nov 20, 2013, 10:48 AM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 10:54 AM EST
Nikos Rak11 reputationPosted Nov 20, 2013, 10:56 AM EST
Nikos Rak11 reputationPosted Nov 20, 2013, 11:09 AM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 11:55 AM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 11:57 AM EST
Nikos Rak11 reputationPosted Nov 20, 2013, 12:01 PM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 12:12 PM EST
I proposed the "Preserving" solution for Unzoom thinking that you mean 'Unzoom' is removing zoom completly at once.
Nikos Rak11 reputationPosted Nov 20, 2013, 12:15 PM EST
Hemant SrivastavaRank #581 · 4.2K reputationPosted Nov 20, 2013, 4:21 PM EST