How to stop updating a PictureBox? [modified]
-
Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:
private void CalcPictureBox1() { // NEED: deactivate pictureBox, that no changes update PictureBox int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor); int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor); if (zoomedWidth > panelDepthBuffer.Width) { this.pBoxDepthBuffer.Left = 0; } else { this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2; } if (zoomedHeight > panelDepthBuffer.Height) { this.pBoxDepthBuffer.Top = 0; } else { this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2; } this.pBoxDepthBuffer.Width = zoomedWidth; this.pBoxDepthBuffer.Height = zoomedHeight; // NEED: activate pictureBox, that changes update PictureBox }
Thank you in advance, Michael
modified on Friday, June 20, 2008 4:33 PM
-
Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:
private void CalcPictureBox1() { // NEED: deactivate pictureBox, that no changes update PictureBox int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor); int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor); if (zoomedWidth > panelDepthBuffer.Width) { this.pBoxDepthBuffer.Left = 0; } else { this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2; } if (zoomedHeight > panelDepthBuffer.Height) { this.pBoxDepthBuffer.Top = 0; } else { this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2; } this.pBoxDepthBuffer.Width = zoomedWidth; this.pBoxDepthBuffer.Height = zoomedHeight; // NEED: activate pictureBox, that changes update PictureBox }
Thank you in advance, Michael
modified on Friday, June 20, 2008 4:33 PM
To update position and size at the same time, you can use...
.SetBounds(left, top, width, height);
[also:
.Scale
may be of use] Hope this helps.Matthew Butler
-
To update position and size at the same time, you can use...
.SetBounds(left, top, width, height);
[also:
.Scale
may be of use] Hope this helps.Matthew Butler
Hi Matthew, thank you for the tip, but it didn't help, whyever. The PictureBox on the panel is still jumping around, when I change it with:
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
...
pBoxDepthBuffer.SizeMode = PictureBoxSizeMode.Zoom;
panelDepthBuffer.Controls.Add(pBoxDepthBuffer);
panelDepthBuffer.AutoScroll = true;...
this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight);
I've also changed the Style of the Form with this.SetStyle to DoubleBuffering. Nothing helped. Do you have any further ideas? Thanks, Michael
-
Hi Matthew, thank you for the tip, but it didn't help, whyever. The PictureBox on the panel is still jumping around, when I change it with:
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
...
pBoxDepthBuffer.SizeMode = PictureBoxSizeMode.Zoom;
panelDepthBuffer.Controls.Add(pBoxDepthBuffer);
panelDepthBuffer.AutoScroll = true;...
this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight);
I've also changed the Style of the Form with this.SetStyle to DoubleBuffering. Nothing helped. Do you have any further ideas? Thanks, Michael
Hi..., I have tried this rude method by setting the image first to null, changing the Bounds and initialalizing the image again:
this.pBoxDepthBuffer.Image = null; this.pBoxDepthBuffer.SetBounds(newLeft, newTop, zoomedWidth, zoomedHeight); this.pBoxDepthBuffer.Image = bitmapDepthBuffer;
This works now for me. Thank you, Michael
-
Hi..., I want to write a zoom function for a PictureBox. Therefore I have to change some values (Left, Top, Width, and Height) of the PictureBox. The PictureBox is redrawn, when I just change one of theses values. So, when I change all 4 values the PictureBox gets flickering and jumping around. How to stop/activate the Redrawing of a PictureBox. This is my code:
private void CalcPictureBox1() { // NEED: deactivate pictureBox, that no changes update PictureBox int zoomedWidth = (int)(bitmapDepthBuffer.Width \* pBoxZoomFactor); int zoomedHeight = (int)(bitmapDepthBuffer.Height \* pBoxZoomFactor); if (zoomedWidth > panelDepthBuffer.Width) { this.pBoxDepthBuffer.Left = 0; } else { this.pBoxDepthBuffer.Left = (panelDepthBuffer.Width - zoomedWidth) / 2; } if (zoomedHeight > panelDepthBuffer.Height) { this.pBoxDepthBuffer.Top = 0; } else { this.pBoxDepthBuffer.Top = (panelDepthBuffer.Height - zoomedHeight) / 2; } this.pBoxDepthBuffer.Width = zoomedWidth; this.pBoxDepthBuffer.Height = zoomedHeight; // NEED: activate pictureBox, that changes update PictureBox }
Thank you in advance, Michael
modified on Friday, June 20, 2008 4:33 PM
I would never bother with a picture box, I'd just draw the bitmap myself.
Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )