1

我正在尝试继承 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不出现。

4

1 回答 1

0

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]我只是通过添加到Properties属性和属性[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]来解决问题Properties.ImageSize

于 2013-03-30T19:16:26.430 回答