WinForms 设计器:添加控件并使其对设计器可见

发布于 2024-08-22 07:09:59 字数 632 浏览 7 评论 0原文

我有一个带有自定义 UI 编辑器的 WinForms 用户控件 Host。 通过该编辑器,可以将子控件 (Child) 添加到 Host

(UI 编辑器创建 Child 并设置 Child.Parent = Host

Child 通过 Holder 辅助类进行处理,该辅助类设置作为例如 ListViewItem 的 Tag 属性。

相应的代码(至少其中一些)被添加到表单中:创建 Holder,并将其设置为 Tag,这也足以在运行时创建。

但是,子级对设计者来说是不可见的 - 它会显示,但无法选择,也不会出现在带有父窗体控件的下拉列表中。

我想:

  • 在设计器中查看 Child 控件,以便我可以修改属性,
  • 并在控件被删除时收到通知

这可能吗?


[编辑]感谢大家的意见。我决定跳过设计师——我希望能快速拼凑出一些东西,但显然这需要更多的计划,而不是我现在应该允许自己花在上面的东西。

I have a WinForms user control Host with a custom UI Editor.
Through that editor, a child control (Child) can be added to Host.

(The UI Editor creates Child and sets Child.Parent = Host)

Child is handled through a Holder<Child> helper class, which is set as Tag property of e.g. a ListViewItem.

The respective code - some of it, at least - gets added to the form: Holder is created, and set as Tag, which is enough to be created at runtime, too.

However, Child is not visible to the designer - it is displayed, but it can't be selected, nor does it occur in the drop down list with controls for the parent form.

I would like to:

  • see the Child control in the designer, so that I can modify properties
  • get notified if the control is removed

Is this possible?


[edit] Thanks all for your input. I've decided to skip the designer - I hoped to throw together something quickly, but apparently it requires more planning than I should allow myself to spend on it right now.

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

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

发布评论

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

评论(2

一抹淡然 2024-08-29 07:09:59

在宿主类上使用this.Controls.Add(/*子级的实例*/);。然后,为通知添加主机 ControlRemoved 事件的事件处理程序 (this.ControlRemoved += new ControlEventHandler(Host_ControlRemoved);)。

Usethis.Controls.Add(/*Instance of the child*/); on the host class. Then for the notification add event handler for the host's ControlRemoved event (this.ControlRemoved += new ControlEventHandler(Host_ControlRemoved);).

岁月流歌 2024-08-29 07:09:59

我不能说我完全理解你想要做什么。

如果您正在处理如何使在设计时放置在窗体上的 UserControl 的“子”控件充当容器的问题,您可以将工具箱中的其他控件拖放到其上:此 CodeProject Henry Minute 的文章可能会有所帮助:设计嵌套控件。例如:您有一个带有面板的 UserControl:UserControl 的实例放置在表单上:在表单的设计时视图中:您希望能够将控件拖放到 UserControl 中的面板上并使它们成为面板的子控件:亨利的文章将向您展示如何做到这一点。

来自 Microsoft 的:如何使用 Visual C# 使 UserControl 对象在设计时充当控件容器

也许也可能有用,尽管您似乎已经完成了这一步。

I can't say I fully understand exactly what you are trying to do.

If you are dealing with the problem of how a "child" Control of a UserControl placed on a Form at Design-Time can be made to function as a container onto which you can drag-and-drop other controls from the Toolbox : this CodeProject article by Henry Minute may be helpful : Designing Nested Controls. For example : you have a UserControl with a Panel inside it : an instance of the UserControl is placed on a Form : in the Design-time view of the Form : you want to be able to drag-drop controls onto the Panel in the UserControl and have them become child controls of the Panel : Henry's article will show you how to do that.

This from Microsoft : How to make a UserControl object acts as a control container design-time by using Visual C#

Perhaps might also be useful, although it seems like you already have this step accomplished.

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