在 Designer 环境中编辑自定义控件或面板
我创建了一个继承 System.Windows.Forms.Panel 的自定义控件,并添加了一些额外的属性。然后,我打算创建继承此自定义面板类的子类,并向它们添加内容。
自定义面板类将被传递到“向导”框架(带有后退/下一步按钮)作为各个步骤的内容。我打算广泛使用它,为 Wizards 创建 40-50 个不同的页面来处理我的项目中的各种事情。
问题:有没有办法在设计器中仅查看面板,并从那里修改其布局和设计?我可以用困难的方式编写所有内容,但我真的不想这样做。
我做了一些搜索,发现这篇文章,但讨论了创建自定义控件和将其添加到库中。我不需要这样做,我只想直接在设计器中查看/编辑控件,而不将其添加到表单中。
I have created a custom control that inherits System.Windows.Forms.Panel, and adds a few extra properties. I then intend to create child classes that inherit this custom-panel class, and add content to them.
The custom-panel class will be passed to a "Wizard" framework (with back/next buttons) as the content for the various steps. I intend to make extensive use of this, creating 40-50 different pages for Wizards to handle various things in my project.
Question: Is there a way to view just the panel in the Designer, and modify its layout and design from there? I could code everything the hard way, but I really don't want to.
I did some searching and found this article, but that discusses creating a custom control and adding it to a library. I don't need to do this, I just want to view/edit the control in Designer directly, without adding it to a Form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
明显的答案再次拯救。
创建自定义控件,根据需要添加布局/拆分面板,并将其属性更改为 DockStyle.Fill。
这使得您的自定义控件的“行为”与布局控件类似,只要您将所有其他控件添加到布局控件即可。
Obvious Answer to the rescue again.
Create a custom control, add the layout/split panel as desired, and change it's property to DockStyle.Fill.
This makes your custom control "behave" like the layout control, as long as you add all other controls to the layout control.
首先添加此名称空间
将
System.ComponentModel.DesignerAttribute
属性应用到控件,如下所示:现在您可以在设计器环境中编辑自定义用户控件
add first this name space
Apply the
System.ComponentModel.DesignerAttribute
attribute to the control as follows:now you can edit your custom user control in designer environment