我正在尝试继承 DevExpress PictureEdit(但是,我认为这个问题不是 DevExpress 特有的)。我添加了一些属性。
public class RepositoryItemFotoEdit:RepositoryItemPictureEdit
{
private Size _imageSize;
public Size ImageSize
{
get
{
return _imageSize;
}
set
{
_imageSize = value;
OnPropertiesChanged();
}
}
[DefaultValue(InterpolationMode.HighQualityBicubic)]
public new InterpolationMode PictureInterpolationMode
{
get { return base.PictureInterpolationMode; }
set { base.PictureInterpolationMode = value; }
}
[DefaultValue(PictureSizeMode.Zoom)]
public new PictureSizeMode SizeMode
{
get { return base.SizeMode; }
set { base.SizeMode = value; }
}
public RepositoryItemFotoEdit()
{
PictureInterpolationMode = InterpolationMode.HighQualityBicubic;
SizeMode = PictureSizeMode.Zoom;
}
}
public sealed class FotoEdit : PictureEdit
{
private FotoMenu _menu;
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_menu != null)
_menu.Dispose();
}
base.Dispose(disposing);
}
public override Image Image
{
get
{
return base.Image;
}
set
{
if(Properties.ImageSize.Width == 0 || Properties.ImageSize.Height == 0 || value == null)
base.Image = value;
else
{
var heightProp = (double) Properties.ImageSize.Height/value.Height;
var widthProp = (double) Properties.ImageSize.Width/value.Width;
var prop = heightProp < widthProp ? heightProp : widthProp;
base.Image = ImageHelper.ResizeImage(value, (int)(prop*value.Width), (int)(prop*value.Height));
}
}
}
public new RepositoryItemFotoEdit Properties
{
get { return base.Properties as RepositoryItemFotoEdit; }
}
protected override PictureMenu Menu
{
get { return _menu ?? (_menu = new FotoMenu(this)); }
}
protected override EditorClassInfo EditorClassInfo
{
get
{
var beci = base.EditorClassInfo;
var eci = new EditorClassInfo("FotoEdit", typeof (FotoEdit), typeof (RepositoryItemFotoEdit),
beci.ViewInfoType, beci.Painter, beci.DesignTimeVisible);
return eci;
}
}
}
属性ImageSize
出现在 PropertyEditor 上。
.
但是,如果我将它更改为某个值(例如 150;150),它不会在表单设计器生成的代码中生成代码。
请注意,这ImageSize
是内部Properties
属性。
//
// fotoEdit1
//
this.fotoEdit1.Cursor = System.Windows.Forms.Cursors.Default;
this.fotoEdit1.Location = new System.Drawing.Point(583, 370);
this.fotoEdit1.Name = "fotoEdit1";
this.fotoEdit1.Size = new System.Drawing.Size(150, 150);
this.fotoEdit1.TabIndex = 18;
这将导致ImageSize
值恢复为 0;0。如何解决这个问题呢?
编辑 :
我试图按照某人的建议添加[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
到财产(我忘记了他的名字,他删除了他的答案)。Properties
这导致属性内Properties
的属性出现在设计器生成的代码中,但那些被覆盖的代码除外。
我的设计器生成的代码如下所示:
//
// fotoEdit1
//
this.fotoEdit1.Cursor = System.Windows.Forms.Cursors.Default;
this.fotoEdit1.Location = new System.Drawing.Point(583, 370);
this.fotoEdit1.Name = "fotoEdit1";
this.fotoEdit1.Properties.Padding = new System.Windows.Forms.Padding(5, 2, 0, 0);
this.fotoEdit1.Size = new System.Drawing.Size(150, 150);
this.fotoEdit1.TabIndex = 18;
注意Properties.Padding
出现,但Properties.ImageSize
不出现。