日期:2014-05-17  浏览次数:20774 次

C#自定义控件事件和委托问题
我正在做一个自定义的listbox控件,我的代码大致如下

....
public class ListItem
    {
        public ListItem() { }
        public ListItem(string songname, int songlenght)
        {
            this.songname = songname;
            this.songlenght = songlenght;
        }
        private string songname;
        private int songlenght; 
        private int alpha = 0;
        private bool focus;
        private EMouseState mouseState;

        private Rectangle bounds;
        public Rectangle Bounds { get { return bounds; } set { bounds = value; } }
        public int Alpha { get { return alpha; } set { alpha = value; } }
        public EMouseState MouseState { get { return mouseState; } set { mouseState = value; } }
        public bool Focus { get { return focus; } set { focus = value; } } 
        public string SongName { get { return songname; } set { songname = value; } }
        public int SongLenght { get { return songlenght; } set { songlenght = value; } }
    }
....
 private List<ListItem> items = new List<ListItem>();
        public List<ListItem> Items
        {
            get
            {
                return items;
            }
        }
...
 protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
            TextFormatFlags SNFlags = TextFormatFlags.VerticalCenter;
            TextFormatFlags SLFlags = TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
            Graphics g = e.Graphics;
          &nb