效果图:
首先添加用户控件(这个根据自己想要的东西来)
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
[Description("属性说明"), Category("自定义分组")]
public bool IsShow
{
get;
set;
}
[Description("属性说明"), Category("自定义分组")]
public bool IsHide
{
get;
set;
}
}
}
另外一种是以类作为属性,再类里面定义属性,话不多说上代码,下面是类
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
[TypeConverter(typeof(ExpandableObjectConverter))]
public class FontOne
{
[NotifyParentProperty(true)]
public bool IsShowOne
{
get;
set;
}
[NotifyParentProperty(true)]
public int Alpha { get; set; }
}
}
下面是控件代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
[Description("属性说明"), Category("自定义分组")]
public bool IsShow
{
get;
set;
}
[Description("属性说明"), Category("自定义分组")]
public bool IsHide
{
get;
set;
}
FontOne _FontOne = new FontOne();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public FontOne FontOne
{
get { return _FontOne; }
set { _FontOne = value; }
}
}
}