首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在设计时作为容器的用户控件

在设计时作为容器的用户控件
EN

Stack Overflow用户
提问于 2010-04-23 06:10:12
回答 3查看 23K关注 0票数 22

我正在设计一个简单的扩展器控件。

我已经从UserControl派生,绘制内部控件,构建,运行;一切都好。

由于内部控件是一个面板,所以我想在设计时将其用作容器。实际上,我已经使用了以下属性:

代码语言:javascript
运行
复制
[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 

我说太棒了。但它不是...

其结果是,我可以在设计时将其用作容器,但是:

  • 添加的控件返回已嵌入到用户控件中的内部控件
  • 即使我将在设计时添加的控件推到顶部,在运行时它也会再次返回到嵌入到用户控件中的控件
  • 我无法在设计时将容器区域限制为面板区域

我遗漏了什么?下面是完整的代码...为什么这段代码不能工作?

代码语言:javascript
运行
复制
[Designer(typeof(ExpanderControlDesigner))]
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
public partial class ExpanderControl : UserControl
{
    public ExpanderControl()
    {
        InitializeComponent();
....

[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] 
internal class ExpanderControlDesigner : ControlDesigner
{
    private ExpanderControl MyControl;

    public override void Initialize(IComponent component)
    {
        base.Initialize(component);

        MyControl = (ExpanderControl)component;

        // Hook up events
        ISelectionService s = (ISelectionService)GetService(typeof(ISelectionService));
        IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));

        s.SelectionChanged += new EventHandler(OnSelectionChanged);
        c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
    }

    private void OnSelectionChanged(object sender, System.EventArgs e)
    {

    }

    private void OnComponentRemoving(object sender, ComponentEventArgs e)
    {

    }

    protected override void Dispose(bool disposing)
    {
        ISelectionService s = (ISelectionService)GetService(typeof(ISelectionService));
        IComponentChangeService c = (IComponentChangeService)GetService(typeof(IComponentChangeService));

        // Unhook events
        s.SelectionChanged -= new EventHandler(OnSelectionChanged);
        c.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);

        base.Dispose(disposing);
    }

    public override System.ComponentModel.Design.DesignerVerbCollection Verbs
    {
        get
        {
            DesignerVerbCollection v = new DesignerVerbCollection();

            v.Add(new DesignerVerb("&asd", new EventHandler(null)));

            return v;
        }
    }
}

我已经找到了很多资源(Interactiondesignedlimited area),但是没有一个是有用的……

实际上有一个技巧,因为System.Windows.Forms类可以(像往常一样)设计并在运行时具有正确的行为(例如TabControl)。

EN

Stack Overflow用户

发布于 2013-03-05 11:56:02

为了防止在设计器中移动工作区/调整其大小,您必须为该工作区创建一个类,该类向设计器隐藏位置、高度、宽度和大小属性:

代码语言:javascript
运行
复制
public class WorkingArea : Panel
{
    [Browsable(false)]
    [EditorBrowsable(EditorBrowsableState.Never)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
    public new Point Location
    {
        get
        {
            return base.Location;
        }
        set
        {
            base.Location = value;
        }
    }
...
}   
票数 3
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2694889

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档