[英]Inherited control not generate code in form designer generated code
I am trying to inherit DevExpress PictureEdit (but, I think this problem is not DevExpress specific). 我正在尝试继承DevExpress PictureEdit(但是,我认为此问题并非特定于DevExpress)。 I add some properties to it. 我添加一些属性。
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;
}
}
}
Property ImageSize
appear on PropertyEditor. 属性ImageSize
出现在PropertyEditor上。
. 。
But, if I change it to some value (eg 150; 150), it is not generate code in form designer generated code. 但是,如果我将其更改为某个值(例如150; 150),则它不是在表单设计器生成的代码中生成的代码。
Note that ImageSize
is inside Properties
property. 请注意, 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;
That will result in ImageSize
value revert back to 0;0. 这将导致ImageSize
值恢复为0; 0。 How to solve this problem? 如何解决这个问题呢?
EDIT : 编辑:
I tried to add [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
to Properties
property as sugested by someone (I forgot his name and he deleted his answer). 我试图将[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
添加到Properties
属性中,因为有人对其提出了建议(我忘记了他的名字,他删除了答案)。 It result to properties inside Properties
property appear in designer generated code except those who overriden. 结果导致Properties
属性出现在设计器生成的代码中,但那些被覆盖的Properties
除外。
My designer generated code look like this: 我的设计师生成的代码如下所示:
//
// 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;
Note that Properties.Padding
appear, but Properties.ImageSize
not. 需要注意的是Properties.Padding
出现,但Properties.ImageSize
没有。
我只是解决了问题补充[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
以Properties
财产和[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
到Properties.ImageSize
财产。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.