我正在尝试继承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
不会显示。
答案 0 :(得分:0)
我只是通过将[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
添加到Properties
属性并将[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
添加到Properties.ImageSize
属性来解决问题。