views:

24

answers:

1

I have a custom control that contains 6 panel controls that act like containers for other controls that are dropped in during design time. This was done by creating a custom designer inheriting from ParentControlDesign. In the designer, I use EnableDesignMode to enable design time functionality for each panel control. The problem is that when I use the control, I can move the panels around. What can I do to prevent them from moving while in design time?

+1  A: 

I couldn't find an ideal solution for this problem, just a partial one. I'll assume you enabled design mode for the panels following the approach in this answer.

Altering the design behavior of the panels requires given them their own designer. Here's a sample class that does this:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Design;

[Designer(typeof(MyPanelDesigner))]
public class MyPanel : Panel {
    private class MyPanelDesigner : ScrollableControlDesigner {
        public override SelectionRules SelectionRules {
            get { return SelectionRules.None; }
        }
    }
}

Replace the panels in your UC with MyPanel. The custom SelectionRules property ensures that the user cannot easily drag the panel into another position with the mouse. The Location and Size properties are however still editable in the property grid. To get rid of that I think you'll need to override PreFilterProperties().

Hans Passant
That worked! Thanks so much!
John_Sheares