Set the size of an image within a picture box?
Solution 1
The CenterImage
option does not allow for scaling etc. Take a look at the PictureBoxSizeMode
Enumeration: http://msdn.microsoft.com/en-us/library/system.windows.forms.pictureboxsizemode.aspx .
You probably want StretchImage
, AutoSize
, or Zoom
Solution 2
Use Padding
property of picture box to resize the picture in picture box
//First Set Size mode property of picture box
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
Then
int padding = 0;
private void btnAddView_Click(object sender, EventArgs e)
{
//resultViewContainer.AddView("Data");
padding += 10;
pictureBox1.Padding = new Padding(padding);
}
private void pictureBox1_PaddingChanged(object sender, EventArgs e)
{
PictureBox pic = sender as PictureBox;
pic.Refresh();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
if (padding >= 10)
{
padding -= 10;
pictureBox1.Padding = new Padding(padding);
}
}
Try to set your image size with the help of padding.. take an idea from this code snippet and implement that you want to do.
rabbitt
Student, studying software design - mainly focused around VB.net, tiniest amount of Android experience. Interested in WP7 development.
Updated on June 04, 2022Comments
-
rabbitt over 1 year
I have a picturebox with a tiled background image (plane white bitmap), and an "image" resource centered in the middle of it, I would like to chance the size of this centered image within the picturebox.
I tried:
picScaledRepresentation.SizeMode = PictureBoxSizeMode.CenterImage picScaledRepresentation.Size = New Size(Width, Height)
But this just changed the the size of the whole picturebox, rather than the image within it.
Thanks, have a good day