我想为继承 (DevExpress.Simple-)Button 的自定义类实现我自己的 Designer-Property。它应该与 ImageIndex-Property 类似,具有图像预览和名称而不是索引号。
我的问题是,我无法选择下拉属性的值。我确定我必须重写 ImgColNamesPropertyGridEditor 类中的一个方法,但我不知道是哪一个。
按钮:
public class CButton1 : DevExpress.XtraEditors.SimpleButton
{
private CImageCollection.Names ICNames = CImageCollection.Names.none;
[Category("Appearance")]
[Browsable(true)]
[DefaultValue(CImageCollection.Names.none)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Editor(typeof(ImgColNamesPropertyGridEditor), typeof(UITypeEditor))]
public CImageCollection.Names ImageName //Names is an Enum
{
get { return ImageNameGetter(); }
set { ImageNameSetter(value); }
}
private CImageCollection.Names ImageNameGetter()
{
CImageCollection imgCol = CImageCollection.Instanz;
if (this.ImageList == imgCol.Imagecollection)//Only if we use our Collection
{
return imgCol.GetEnumFromIndex(this.ImageIndex);
}
return CImageCollection.Names.none;
}
private void ImageNameSetter(CImageCollection.Names value)
{
CImageCollection imgCol = CImageCollection.Instanz;
if (this.ImageList == imgCol.Imagecollection)//Only if we use our Collection
{
ICNames = value;
this.ImageIndex = imgCol.GetIndexFromEnum(value);
}
}
public CButton1()
{
CImageCollection imgcol = CImageCollection.Instanz;
this.ImageList = imgcol.Imagecollection;
}
}
UITypeEditor:
class ImgColNamesPropertyGridEditor : UITypeEditor
{
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
//Set to true to implement the PaintValue method
return true;
}
public override void PaintValue(PaintValueEventArgs e)
{
CImageCollection col = CImageCollection.Instanz;
string _SourceName = col.GetEnumFromIndex((int)e.Value).ToString("g");
//Draw the corresponding image
Bitmap newImage = (Bitmap)CButtonRes.ResourceManager.GetObject(_SourceName);
Rectangle destRect = e.Bounds;
newImage.MakeTransparent();
e.Graphics.DrawImage(newImage, destRect);
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
return base.EditValue(context, provider, value);
}
}