(DevExpress.Simple-)Buttonを継承するカスタムクラス用に独自のDesigner-Propertyを実装したいと思います。インデックス番号の代わりに画像と名前のプレビューを備えたImageIndex-Propertyと同様に機能するはずです。
私の問題は、DropDown-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);
}
}