Flicker free TableLayoutPanel

If you are using the TableLayoutPanel from the .NET framework and want to reduce the flickering when resizing, you could enable double-buffering by sub-classing the TableLayoutPanel class.

When double buffering is enabled, all paint operations are first rendered to a memory buffer instead of the drawing surface, this will heavily reduce flickering.

Replace any references to the TableLayoutPanel with reference to the newly created TableLayoutPanelDoubleBuffered class.

public class TableLayoutPanelDoubleBuffered : TableLayoutPanel
    {
        public TableLayoutPanelDoubleBuffered()
        {
            this.DoubleBuffered = true;
        }
    }

Handling collections in PropertyGrid

To detect if the collection editor for the .NET PropertyGrid has the OK or Cancel button clicked you can use the below code and subscribe to the MyFormOK or MyFormCancel events.

public class MyCollectionEditor : CollectionEditor
   {
       public delegate void MyFormClosedEventHandler(object sender, FormClosedEventArgs e);
       public delegate void MyFormCancelEventHandler(object sender);
 
       public static event MyFormClosedEventHandler MyFormOK;
       public static event MyFormCancelEventHandler MyFormCancel;

       private bool cancel;

       public MyCollectionEditor(Type type) : base(type) { }

       protected override CollectionForm CreateCollectionForm()
       {
           CollectionForm collectionForm = base.CreateCollectionForm();
           collectionForm.FormClosed += new FormClosedEventHandler(collection_FormClosed);
           cancel = false;
           return collectionForm;
       }
       
       protected override void CancelChanges()
       {
           if (MyFormCancel != null)
           {
               MyFormCancel(this);
           }
           cancel = true;
           base.CancelChanges();
       }

       void collection_FormClosed(object sender, FormClosedEventArgs e)
       {
           if (MyFormOK != null && !cancel)
           {
               MyFormOK(this, e);
           }
       }
   }

 

Activate the enhanced MyCollection editor:

[Editor(typeof(MyCollectionEditor), typeof(UITypeEditor))]
public List<Person> UserList { getset; } = new List<Person>();