Editing Custom Controls or Panels in the Designer environment

非 Y 不嫁゛ 提交于 2021-01-29 08:49:04

问题


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.


回答1:


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.




回答2:


add first this name space

using System.ComponentModel.Design;

Apply the System.ComponentModel.DesignerAttribute attribute to the control as follows:

[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))] 
public class UserControl1 : System.Windows.Forms.UserControl
{
      ...
}

now you can edit your custom user control in designer environment



来源:https://stackoverflow.com/questions/7704548/editing-custom-controls-or-panels-in-the-designer-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!