Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

How to resize an image depending on picture box size?

What I have tried:

var filePath = "C:\\Images\\images.jpg";
            Bitmap bmap = new Bitmap(filePath);
            picturebox.Image = bmap;
            picturebox.BorderStyle = BorderStyle.Fixed3D;
            picturebox.SizeMode = PictureBoxSizeMode.AutoSize;
            picturebox.Location = new System.Drawing.Point(0, (int)((0.05 * screenHeight)));
            picturebox.Size = new System.Drawing.Size(screenWidth, (int)((0.13 * screenHeight) - 2));


screenheight and screenwidth will be PCs resolution
Posted
Updated 5-Feb-21 2:00am
v2

1 solution

Try setting the PictureBox.SizeMode Property (System.Windows.Forms) | Microsoft Docs[^] to StretchImage instead of AutoSize - it sizes the image to the container, instead of the container to the image.
PictureBoxSizeMode Enum (System.Windows.Forms) | Microsoft Docs[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900