Search code examples
c#winformsdrag-and-dropdouble-buffering

Drag And Drop events are interrupting smooth motion of GUI when scrolling


I have a splitContainer control.
inside one of the splitContainer panels there is a FlowlayoutPanel configured with AutoScroll=True.
the FlowLayoutPanel contains ~200 controls (so the user must scroll in order to communicate with all the controls).
each control is made of FlowLayoutPanel parent that has 3 child's of FlowLayoutPanels inside him, each child has 2 Label child's inside him. all the Labels invoke "Drag" Events:

    private void Vcont_MouseEnter(object sender, EventArgs e)
    {
       System.Windows.Forms.Control c = sender as System.Windows.Forms.Control;
       c.DoDragDrop(c, System.Windows.Forms.DragDropEffects.Move);
    }

    private void Vcont_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
    {
        e.Effect = System.Windows.Forms.DragDropEffects.All;
    }

the Form is set to DoubleBuffered=True and i wrote extension methods for each control (splitContainer,flowlayoutpanels and labels) in order to set the DoubleBuffered Property to true , for example:

public static class ExtensionMethods
{
   public static void DoubleBuffered_FlPanel(this FlowLayoutPanel fp, bool setting)
    {
        Type type = fp.GetType();
        PropertyInfo pi = type.GetProperty("DoubleBuffered",
            BindingFlags.Instance | BindingFlags.NonPublic);
        pi.SetValue(fp, setting, null);
    }
}

My question: UX experience is negatively affected because controls are flickering and screen get stack while scrolling and it feels poor quality. i have discovered that if i`m commenting the Drag&Drop events, GUI behave drastically better. how can i invoke those events for each control without damaging the user experience?

thank you.


Solution

  • Don't use the MouseEnter event to initiate drag & drop. The typical method is to use the MouseDown event.

    I ran a quick test using MouseEnter, and it is hit repeatedly while the mouse is within the control. It appears that initiating the drag causes the Mouse to leave the control. These multiple event firings are likely a large part of your issue.