views:

56

answers:

1

Hi there!

I'm coding an app where I display a System.Drawing.Icon object on a System.Windows.Forms.Panel using a code that goes something like so:

Graphics g = _panel.CreateGraphics();
g.DrawIcon(this.NodeIcon, _rectangle);

I have code to move the icon around using drag-n-drop. My problem is that when the user move the icon around, it is anything but smooth. The icon looks distorted until the user stops moving the icon.

I have tried to find information on this around the net but I can't get it to be smooth. I have little previous experience of this particular kind of coding (using graphics) so I am a rookie to this.

If any kind soul could help me with some hints it would be much appreciated.

Thanks in advance!

A: 

I believe what you're trying to do is to redraw your control on the MouseMove event handler. And looks like your problem is the flicker when redrawing the panel. First what you can try to do is set true to DoubleBuffered property of your panel. Doing this you would set the panel to redraw its surface using a secondary buffer to reduce or prevent flicker. This property is protected so you would need to create a new panel descendant:

public class TestPanel : Panel
{
  public TestPanel()
  {
     DoubleBuffered = true;
  }
}

as an alternative you can set the DoubleBuffered property for your panel through reflection

hope this helps, regards

serge_gubenko
Thank you for your comment. I will try this as well as the other tips from the other comments. When I've cracked the problem I will let you know.
Freddy
Thanks! I finally had the time to test these tips and the DoubleBuffered did what I needed. Thanks again!
Freddy