简体   繁体   中英

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). 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.

在此处输入图片说明 .

But, if I change it to some value (eg 150; 150), it is not generate code in form designer generated code.

Note that ImageSize is inside Properties property.

// 
// 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. 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). It result to properties inside Properties property appear in designer generated code except those who overriden.

在此处输入图片说明

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.

我只是解决了问题补充[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]Properties财产和[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]Properties.ImageSize财产。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM