自带面板组件

发布于 2024-08-28 15:20:24 字数 206 浏览 8 评论 0原文

我想创建我自己的组件,其中包含另外两个面板。其中一个有固定的内容(例如控制按钮等),另一个是标准面板,我可以在设计器(VS2008)中添加其他组件。 我知道我必须创建 UserControl,我可以在其中放置两个面板。然后我想将我的组件插入表单中。但我不知道如何创建只能将其他组件(例如按钮、标签等)添加到组件中的第二个面板中的行为。 有人可以帮我创建这个组件吗?

谢谢。 亚当.

I want to create my own component which consists two other panels. One of them has fixed contents (such as control buttons, etc.) and the other is standard panel, where I can add other components in designer (VS2008).
I know that I have to create UserControl, where I can place my two panels. Then I want to insert my component into the form. But I don't know how to create behavior where I can add other components (such as buttons, labels, etc.) only into second panel in my component.
Could anyone help me with creating this component?

Thank you.
Adam.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与他有关 2024-09-04 15:20:24

这是一个示例(工作代码片段):

  [Designer(typeof(NavigationalUserControl.Designer))]
  public partial class NavigationalUserControl : UserControl
  {
    class Designer : ControlDesigner 
    {
      public override void Initialize(IComponent component)
      {
        base.Initialize(component);
        var nc = component as NavigationalUserControl;
        EnableDesignMode(nc.panel2, "ContainerPanel"); 
        EnableDesignMode(nc.bottomPanel, "BottomPanel");
      }
    }

    // rest of normal class
  }

Here is an example (snippet of working code):

  [Designer(typeof(NavigationalUserControl.Designer))]
  public partial class NavigationalUserControl : UserControl
  {
    class Designer : ControlDesigner 
    {
      public override void Initialize(IComponent component)
      {
        base.Initialize(component);
        var nc = component as NavigationalUserControl;
        EnableDesignMode(nc.panel2, "ContainerPanel"); 
        EnableDesignMode(nc.bottomPanel, "BottomPanel");
      }
    }

    // rest of normal class
  }
要走干脆点 2024-09-04 15:20:24

我已经找到了正确的解决方案(我希望)。我已在我的 UserControl 中添加了一个属性,该属性返回具有此特定属性的内容面板:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel PanelContent
{
   get { return this.panel2; }
}

感谢您的帮助 leppie

I have found the correct solution (I hope). I have added into my UserControl a property which returns the content panel with this specific Attribute:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Panel PanelContent
{
   get { return this.panel2; }
}

Thanks for your help leppie

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文