1

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.

Jonathan Applebaum
  • 5,738
  • 4
  • 33
  • 52
  • Have you tried running a profiler against your application? My feeling is that `DoubleBuffered_FlPanel` is going to be your problem. That method there is millions of times slower than anything else in your application. Reflection should NEVER be done on your UI thread. – Aron Mar 01 '17 at 01:25
  • @Aron I had that concern, i will diagnose it, thank you for your advice and for the lighting up: Reflection should NEVER be done on your UI thread – Jonathan Applebaum Mar 01 '17 at 01:30
  • Why are you using the MouseEnter event to initiate D&D. 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 part of your issue. – TnTinMn Mar 01 '17 at 16:15
  • @TnTinMn that is exactly the conclusion that i had this morning, changed it to `MouseEnter` event and everything is working properly. that is the answer, please write it as an answer if you like. – Jonathan Applebaum Mar 01 '17 at 17:23

1 Answers1

3

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.

TnTinMn
  • 11,522
  • 3
  • 18
  • 39