Re: Distorted image when scrolling in DoubleBufferPanel
- From: "Peter Duniho" <no.peted.spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 02 Sep 2009 21:03:15 -0700
On Wed, 02 Sep 2009 19:58:46 -0700, moss <mdtopic@xxxxxxxxx> wrote:
Hi,
i have a UserControl called DoubleBufferPanel which is a typical Panel
but is set to be DoubleBuffered by the SetStyle() method. I draw my
images on that Panel and no clipping occurs, but when I set it to
AutoScroll and begin scrolling, the image becomes distorted like this:
http://www.flickr.com/photos/37459057@N04/3882558185/
The "distortion" is simply bits of your image being left in an undrawn area of the control.
By the way, I could see inherited Panel (to get the scrollbars automatically), but I don't see the point in inheriting UserControl, nor is it clear from your question whether you are actually inheriting Panel or UserControl.
When I resize the form which contains the panel and when I size the
image to fit the panel's dimensions everything is ok, but when I
scroll in any direction this kind of distortion keeps appearing. I
used this code to set the AutoScroll and draw the image:
this.imagePanel.AutoScroll = true;
this.imagePanel.AutoScrollMinSize = MyBitmap.Size;
g.DrawImage(MyBitmap, new RectangleF
(this.imagePanel.AutoScrollPosition.X, this.AutoScrollPosition.Y,
MyBitmap.Width, MyBitmap.Height));
What is the cause of this problem and how can it be solved?
Impossible to say for sure without a concise-but-complete code example that reliably demonstrates the problem. There are too many possible reasons for this kind of redraw problem to occur. But, I suspect based on the code and picture that you've shown that you aren't limiting scrolling to having the bottom edge of the bitmap appear no higher than the bottom edge of the control, and thus when you redraw, nothing that would erase or otherwise redraw the area not part of the bitmap happens, so you just get the left-over bits from the stuff that was drawn before.
If so, the solution would be to either make sure something is drawn there (e.g. erase to the background color) or limit scrolling so that the image never is scrolled far enough for there to be parts of the control not drawn when you draw the image.
If none of that seems to apply, you should post a concise-but-complete code example that reliably demonsrates the problem. That way, it would be possible for someone to know what the code is actually doing, and thus have some idea as to how to fix it.
Pete
.
- Follow-Ups:
- References:
- Prev by Date: Re: Creating a Decorator Using System.Reflection.Emit
- Next by Date: Entity Framework Extension
- Previous by thread: Distorted image when scrolling in DoubleBufferPanel
- Next by thread: Re: Distorted image when scrolling in DoubleBufferPanel
- Index(es):
Relevant Pages
|