Reputation: 2598
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
Upvotes: 2
Views: 16770
Reputation: 18290
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.
Upvotes: 1
Reputation: 2023
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
Upvotes: 3