Zooming picturebox not updating
-
Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
System.Threading.Thread.Sleep(1000);
}
}private void zoomOutPicture(int zoomF)
{
int myHeight = 100+zoomF;
int myWith = 70 + (int)Math.Round(zoomF * .7, 0);System.Drawing.Size test; test = new System.Drawing.Size(myWith, myHeight); myPictureBox.Size = test;
}
I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.
-
Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
System.Threading.Thread.Sleep(1000);
}
}private void zoomOutPicture(int zoomF)
{
int myHeight = 100+zoomF;
int myWith = 70 + (int)Math.Round(zoomF * .7, 0);System.Drawing.Size test; test = new System.Drawing.Size(myWith, myHeight); myPictureBox.Size = test;
}
I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.
Hi, I tried your code on my machine .Net 2.0 vs2005 and it seems to work fine. I added a line that refreshes the form so maybe try this and see if the results are any different.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
this.Refresh(); // <---- line added that references the form with the picture box on it
System.Threading.Thread.Sleep(1000);
}
}Dave
-
Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
System.Threading.Thread.Sleep(1000);
}
}private void zoomOutPicture(int zoomF)
{
int myHeight = 100+zoomF;
int myWith = 70 + (int)Math.Round(zoomF * .7, 0);System.Drawing.Size test; test = new System.Drawing.Size(myWith, myHeight); myPictureBox.Size = test;
}
I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.
-
Hi, I am trying to create a function that when called takes a pictureBox and make it larger in 5 steps. My problem is that when I run the function the pictureBox is not updated until the last step where the pictureBox is full size. The picture box is called myPictureBox and has a size of 70,100 at the beginning.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
System.Threading.Thread.Sleep(1000);
}
}private void zoomOutPicture(int zoomF)
{
int myHeight = 100+zoomF;
int myWith = 70 + (int)Math.Round(zoomF * .7, 0);System.Drawing.Size test; test = new System.Drawing.Size(myWith, myHeight); myPictureBox.Size = test;
}
I have spent the last 3 hours searching with out any luck so any help is greatly apriciated. Thank you.
you could "solve" it with some Invalidate() or Refresh() calls, but your approach is fundamentally flawed, since you are blocking the GUI thread for the entire duration of this action, making moving, resizing, e.a. impossible. The correct approach is by using either a separate thread or a timer; since the actions involve Controls, which need to be handled on the main thread anyway, your best option is to start a Windows.Forms.Timer :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
-
Hi, I tried your code on my machine .Net 2.0 vs2005 and it seems to work fine. I added a line that refreshes the form so maybe try this and see if the results are any different.
private void button1_Click(object sender, EventArgs e)
{
for (int j = 0; j < 5; j++)
{
zoomOutPicture((j + 1) * 10);
this.Refresh(); // <---- line added that references the form with the picture box on it
System.Threading.Thread.Sleep(1000);
}
}Dave
-
you could "solve" it with some Invalidate() or Refresh() calls, but your approach is fundamentally flawed, since you are blocking the GUI thread for the entire duration of this action, making moving, resizing, e.a. impossible. The correct approach is by using either a separate thread or a timer; since the actions involve Controls, which need to be handled on the main thread anyway, your best option is to start a Windows.Forms.Timer :)
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.