用户控件需要一些图标……我想写个属性可以自己确定用哪些!
image 和 imagelist 我都试了下!没结果!
其实就是一个图片组,但image是抽象类……
高手给个提示……

解决方案 »

  1.   

    把图标资源放到用户资源里 然后引用就可以了 没必要放到image 或者imagelist
      

  2.   

    设个属性让用户选择吧,像PictureBox中的Image一样
      

  3.   


    image属性可以,但是image[]不行……抽象类不能实例化
      

  4.   

     OpenFileDialog OpenFile= new OpenFileDialog();
                OpenFile.Filter = "ico文件(*.ico)|*.ico|所有文件(*.*)|*.*";
                OpenFile.ShowDialog(); 
     OpenFileDialog open 事件
      Bitmap bmp = new Bitmap(OpenFile.FileName);  
    Cotrol.Image = Image(bmp);
      

  5.   

    我是猎头公司的angel,目前有.net的职位需求,要求有:5年左右的相关经验,英文能进行英文面试,base:shanghai,
    有感兴趣的联系我
    email: [email protected]
    msn: [email protected]
      

  6.   

    是自定义控件自己的ICo
    还是自定义控件里某个控件的图片 
      

  7.   


    是自定义控件中一个树导航中每个item的图标……
    肯定有多个…不限定数量
      

  8.   

     System.Collections.Generic.List<System.Drawing.Image>
      

  9.   


    泛型我试过了……貌似image是个抽象类!
    这样好像不行……
    可能是我错了……再试试去!
    还是要等高手
      

  10.   

    lz参考以下测试代码:
    基本上实现了MS风格的Image和ImageList属性,
    Image属性可以使用图片设定,ImageList属性可以使用MS标准的ImageList控件。using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;
    using System.Drawing.Design;namespace testApp
    {
        public class UserControl1 : UserControl
        {
            private System.ComponentModel.IContainer components = null;
            public UserControl1()
            {
                InitializeComponent();
            }
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Properties
            private ImageIndexer _imageIndexer = null;
            private ImageIndexer ImageIndexer
            {
                get
                {
                    if (this._imageIndexer == null)
                    {
                        this._imageIndexer = new ImageIndexer();
                    }
                    return this._imageIndexer;
                }
            }
            
            private Image _image = null;
            [Localizable(true)]
            [Description("Image")]
            [Category("Appearance")]
            public Image Image
            {
                get
                {
                    if ((this._image == null) && (this._imageList != null))
                    {
                        int index = this.ImageIndexer.ActualIndex;
                        if (index >= this._imageList.Images.Count)
                        {
                            index = this._imageList.Images.Count - 1;
                        }
                        if (index >= 0)
                        {
                            return this._imageList.Images[index];
                        }
                    }
                    return this._image;
                }
                set
                {
                    if (this.Image != value)
                    {
                        this.StopAnimate();                    if (value != null)
                        {
                            this.ImageIndex = ImageIndexer.DefaultImageIndex;
                            this.ImageKey = string.Empty;
                            this.ImageList = null;
                        }                    this._image = value;                    this.PerformLayout();
                        this.Animate();
                        this.Refresh();
                    }
                }
            }
            private bool ShouldSerializeImage()
            {
                return (this._image != null);
            }
            private void ResetImage()
            {
                this.Image = null;
            }        private ImageList _imageList = null;
            [DefaultValue((string)null)]
            [Description("ImageList")]
            [Category("Appearance")]
            public ImageList ImageList
            {
                get
                {
                    return this._imageList;
                }
                set
                {
                    if (this._imageList != value)
                    {
                        if (this._imageList != null)
                        {
                            this._imageList.RecreateHandle -= new EventHandler(this.OnImageListRecreateHandle);
                            this._imageList.Disposed -= new EventHandler(this.OnDetachImageList);
                        }                    if (value != null)
                        {
                            value.RecreateHandle += new EventHandler(this.OnImageListRecreateHandle);
                            value.Disposed += new EventHandler(this.OnDetachImageList);                        this.StopAnimate();
                            this._image = null;
                        }                    this._imageList = value;
                        this.ImageIndexer.ImageList = value;                    this.PerformLayout();
                        this.Refresh();
                    }
                }
            }        [Localizable(true)]
            [DefaultValue(ImageIndexer.DefaultImageIndex)]
            [TypeConverter(typeof(ImageIndexConverter))]
            [Editor("System.Windows.Forms.Design.ImageIndexEditor", typeof(UITypeEditor))]
            [Description("ImageIndex")]
            [Category("Appearance")]
            public int ImageIndex
            {
                get
                {
                    if (((this.ImageIndexer.Index != ImageIndexer.DefaultImageIndex) && (this._imageList != null)) && (this.ImageIndexer.Index >= this._imageList.Images.Count))
                    {
                        return (this._imageList.Images.Count - 1);
                    }
                    return this.ImageIndexer.Index;
                }
                set
                {
                    if (this.ImageIndexer.Index != value)
                    {
                        if (value != ImageIndexer.DefaultImageIndex)
                        {
                            this.StopAnimate();
                            this._image = null;
                        }
                        this.ImageIndexer.Index = value;                    this.PerformLayout();
                        this.Refresh();
                    }
                }
            }        [Localizable(true)]
            [DefaultValue("")]
            [Editor("System.Windows.Forms.Design.ImageIndexEditor", typeof(UITypeEditor))]
            [TypeConverter(typeof(ImageKeyConverter))]
            [Description("ImageIndex")]
            [Category("Appearance")]
            public string ImageKey
            {
                get
                {
                    return this.ImageIndexer.Key;
                }
                set
                {
                    if (this.ImageIndexer.Key != value)
                    {
                        if (value != null)
                        {
                            this.StopAnimate();
                            this._image = null;
                        }
                        this.ImageIndexer.Key = value;                    this.PerformLayout();
                        this.Refresh();
                    }
                }
            }
            #endregion        #region Events & Methods
            internal event EventHandler ImageListRecreateHandle = null;
            private void OnImageListRecreateHandle(object sender, EventArgs args)
            {
                if (this.ImageListRecreateHandle != null)
                {
                    this.ImageListRecreateHandle(this, args);
                }
            }
            
            internal event EventHandler DetachImageList = null;
            private void OnDetachImageList(object sender, EventArgs args)
            {
                if (this.DetachImageList != null)
                {
                    this.DetachImageList(this, args);
                }
            }
            #endregion
    ......
      

  11.   

            #region Private Methods
            private bool _isAnimation = false;
            private void Animate(bool animate)
            {
                if (animate != this._isAnimation)
                {
                    Image image = this.Image;
                    if (animate)
                    {
                        if (image != null)
                        {
                            ImageAnimator.Animate(image, new EventHandler(this.OnFrameChanged));
                            this._isAnimation = animate;
                        }
                    }
                    else if (image != null)
                    {
                        ImageAnimator.StopAnimate(image, new EventHandler(this.OnFrameChanged));
                        this._isAnimation = animate;
                    }
                }
            }
            private void OnFrameChanged(object sender, EventArgs e)
            {
                if (this.InvokeRequired)
                {
                    this.BeginInvoke(new EventHandler(this.OnFrameChanged), new object[] { sender, e });
                }
                else
                {
                    this.Refresh();
                }
            }        private void Animate()
            {
                this.Animate((!this.DesignMode && this.Visible) && this.Enabled);
            }
            private void StopAnimate()
            {
                this.Animate(false);
            }        private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            }
            #endregion        #region Paint Methods
            protected override void OnPaint(PaintEventArgs e)
            {
                base.OnPaint(e);
                this.DrawImage(e.Graphics, this.ClientRectangle);
            }
            private void DrawImage(Graphics graphics, Rectangle bounds)
            {
                this.Animate();
                ImageAnimator.UpdateFrames();            if (this.Image != null && bounds.Width > 0 && bounds.Height > 0)
                {
                    using (Region oldRegion = graphics.Clip)
                    {
                        graphics.SetClip(bounds, CombineMode.Intersect);
                        graphics.DrawImageUnscaledAndClipped(this.Image, bounds);
                        graphics.Clip = oldRegion;
                    }
                }
            }
            #endregion
        }
      

  12.   

        internal class ImageIndexer
        {
            #region Const Data
            internal const int DefaultImageIndex = -1;
            #endregion        #region Instance Data
            private string _key = string.Empty;
            private int _index = DefaultImageIndex;
            private bool _useIntegerIndex = true;
            private ImageList _imageList;
            #endregion        #region Constructor
            public ImageIndexer()
            {
            }
            #endregion        #region Properties
            public virtual int ActualIndex
            {
                get
                {
                    if (this._useIntegerIndex)
                    {
                        return this.Index;
                    }
                    if (this.ImageList != null)
                    {
                        return this.ImageList.Images.IndexOfKey(this.Key);
                    }
                    return DefaultImageIndex;
                }
            }
            public virtual ImageList ImageList
            {
                get
                {
                    return this._imageList;
                }
                set
                {
                    this._imageList = value;
                }
            }
            public virtual int Index
            {
                get
                {
                    return this._index;
                }
                set
                {
                    this._key = string.Empty;
                    this._index = value;
                    this._useIntegerIndex = true;
                }
            }
            public virtual string Key
            {
                get
                {
                    return this._key;
                }
                set
                {
                    this._index = DefaultImageIndex;
                    this._key = (value == null) ? string.Empty : value;
                    this._useIntegerIndex = false;
                }
            }
            #endregion
        }
    }
      

  13.   

    我是楼主!其实只要实现这样的一个效果! private Image[] _image;       
     public Image[] _Image
      {
        ……
       }但是image[]不能这样写……所以请大家帮忙!
    换个思路…………
      

  14.   

    18-20楼的代码实现了Image,ImageIndex,ImageKey,ImageList几个属性并且实现了Image属性和其他属性之间的联动关系;
    也演示了图片的简单的画法;如果lz只是为了存储目的而不关心Image如何绘制可以参照:
    private ImageList _images = null;
    public ImageList Images
    {
        get
        {
            if (this._images == null)
            {
                this._images = new ImageList();
            }
            return this._images;
        }
    }
    这样的实现可以实现存储图片并且也支持在设计时功能。