要实现如下的属性为下拉属性:
namespace My_Controls.Controls
{
public partial class UCImageSource
{
private string defaultBtnType = "";
public class BtnTypeConverter: StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new string[]{
"ImageSource",
"Binarization",
"Contour",
});
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}
}
// The TypeConverter attribute applied to the defaultBtnType property.
[TypeConverter(typeof(BtnTypeConverter)),
CategoryAttribute("自定义")]
public string BtnType
{
get { return defaultBtnType; }
set { defaultBtnType = value; }
}
}
}