怎么定义嵌套属性,请各位高手指教(100分)
设计控件时,想定义一个属性,类似于Font之类的,在设计时能展开子属性直接设计。
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Public.Windows.Forms
{
/// <summary>
/// MonthCalendarCN 的摘要说明。
/// </summary>
public class MonthCalendarCN : System.Windows.Forms.Control
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private Style FTitleStyle ;
public MonthCalendarCN()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitComponent 调用后添加任何初始化
FTitleStyle = new Style();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: 在此添加自定义绘画代码
// 调用基类 OnPaint
base.OnPaint(pe);
}
[DescriptionAttribute("help"),EditorAttribute()]
public Style TilteStyle
{
get
{
return FTitleStyle;
}
set
{
FTitleStyle = value;
}
}
}
}
using System;
using System.Drawing;
namespace Public.Windows.Forms
{
/// <summary>
/// Style 的摘要说明。
/// </summary>
[Serializable]
public class Style : MarshalByRefObject
{
private Font FFont ;
private Color FBackColor ;
private Color FForeColor ;
private Image FBackgroundImage;
public Style()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/*public Font Font
{
get
{
return FFont ;
}
set
{
FFont = value ;
}
}*/
public Color BackColor
{
get
{
return FBackColor ;
}
set
{
FBackColor = value ;
}
}
public Color ForeColor
{
get
{
return FForeColor ;
}
set
{
FForeColor = value ;
}
}
/*public Image BackgroundImage
{
get
{
return FBackgroundImage;
}
set
{
FBackgroundImage = value;
}
}*/
}
}
上面的TilteStyle 就是嵌套属性,但在设计时,该属性显示为灰色,左边也没有加号。是不是要定义EditorAttribute这些特性呀?谁有例子帮帮忙