开发者

How prevent container control from being moved in user control during design-time?

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 mov开发者_如何学Goe the panels around. What can I do to prevent them from moving while in design time?


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().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜