Re: Distorted image when scrolling in DoubleBufferPanel

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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
.



Relevant Pages

  • Panel drawing problems.
    ... Draw recieved values to a panel so values are displayed countiniously as a ... scrolling graph. ... draw it back -1 position to the left. ... h))); // clear plot region ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: "AutoScroll event" in Panel
    ... I had a problem with adding a new usercontrol to a panel and scrolling ... did this when the form loads: ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Binding custom list of usercontrols?
    ... collection and want the Panel to create a UserControl for each business ... You set up data binding between the UserControl ... and the corresponding business object. ... private void RearrangeTextBoxes() ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • RE: GDI+ Clip Region allows 0.0f width pen to draw through
    ... Just to make this more outrageous if you draw the vertical lines from the ... I took the previous code I posted and made the panel anchor to all four ... private void panel1_SizeChanged ... In other words create a rectangle that is a wider than the panel. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: Flowlayout, JPanel and JScrollPane: Scrolling vertically impossible?
    ... >> JScrollPane using FlowLayout. ... >> enable wrapping, and when components inside the panel go out of view, ... > scrolling). ... > (And therefore the preferredSize value returned by the panel would ...
    (comp.lang.java.gui)