public void Insert(int index, StudyPlanListBoxItem item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     Owner.OldItems.Insert(index, item);
 }
 public int Add(StudyPlanListBoxItem item)
 {
     if (item == null)
     {
         throw new ArgumentException("item");
     }
     return(Owner.OldItems.Add(item));
 }
 public void Remove(StudyPlanListBoxItem item)
 {
     Owner.OldItems.Remove(item);
 }
 public void Insert(int index, StudyPlanListBoxItem item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     Owner.OldItems.Insert(index, item);
 }
 public int IndexOf(StudyPlanListBoxItem item)
 {
     return Owner.OldItems.IndexOf(item);
 }
 public void CopyTo(StudyPlanListBoxItem[] destination, int arrayIndex)
 {
     Owner.OldItems.CopyTo(destination, arrayIndex);
 }
 public bool Contains(StudyPlanListBoxItem item)
 {
     return Owner.OldItems.Contains(item);
 }
 public int Add(StudyPlanListBoxItem item)
 {
     if (item == null)
     {
         throw new ArgumentException("item");
     }
     return Owner.OldItems.Add(item);
 }
 /// <summary>
 /// 选中项被改变事件
 /// </summary>
 /// <param name="e"></param>
 protected override void OnSelectedIndexChanged(EventArgs e)
 {
     mMouseItem = Items[SelectedIndex];
     Invalidate();
     base.OnSelectedIndexChanged(e);
 }
        /// <summary>
        /// 引发 MouseMove 事件
        /// </summary>
        /// <param name="e">包含事件数据的 MouseEventArgs</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            bool isChange = false;  // 指示是否改变
            Rectangle bounds;
            // 轮询表项
            for (int i = 0; i < Items.Count; i++)
            {
                bounds = GetItemRectangle(i);
                if (bounds.Contains(e.X, e.Y))
                {
                    if (e.X > 445 && e.X < 545 && e.Y > (27 + bounds.Y) && e.Y < (57 + bounds.Y))
                    {
                        if (buttonHighlightIndex != i)
                        {
                            buttonHighlightIndex = i;
                            isChange = true;
                        }
                    }
                    else if (e.X > 330 && e.X < 410 && e.Y > (45 + bounds.Y) && e.Y < (64 + bounds.Y))
                    {
                        buttonDownIndex = -1;
                        if (Cursor != Cursors.Hand)
                        {
                            Cursor = Cursors.Hand;
                            if (Items[i] != mMouseItem)
                                mMouseItem = Items[i];
                            break;
                        }
                    }
                    else
                    {
                        buttonDownIndex = -1;
                        if (Cursor != Cursors.Arrow)
                            Cursor = Cursors.Arrow;

                        if (buttonHighlightIndex == i)
                        {
                            buttonHighlightIndex = -1;
                            isChange = true;
                        }
                    }

                    if (Items[i] != mMouseItem)
                    {
                        mMouseItem = Items[i];
                        isChange = true;
                    }
                }

                if (isChange)
                    break;
            }

            // 判断鼠标指针是否悬浮在空白区域
            if (Items.Count > 0)
            {
                bounds = GetItemRectangle(Items.Count - 1);
                if (e.Y > (65 + bounds.Y))
                {
                    if (Cursor != Cursors.Arrow)
                        Cursor = Cursors.Arrow;
                }

                if (isChange)
                    Invalidate();
            }
            base.OnMouseMove(e);
        }
        /// <summary>
        /// 引发 Paint 事件
        /// </summary>
        /// <param name="e">包含事件数据的 PaintEventArgs</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            // 获取绘制对象
            Graphics g = e.Graphics;

            // 循环绘制每项
            for (int i = 0; i < Items.Count; i++)
            {
                Rectangle            bounds = GetItemRectangle(i);
                StudyPlanListBoxItem item   = Items[i];
                // 绘制表项分界线
                Pen p = new Pen(Brushes.LightGray);
                //p.DashStyle = DashStyle.Dash;
                g.DrawLine(p, new Point(0, bounds.Top), new Point(Width, bounds.Top));
                // 绘制表项背景
                if (SelectedIndex != i)
                {
                    Color backColor = Color.FromArgb(20, 216, 211, 211);
                    using (SolidBrush brush = new SolidBrush(backColor))
                    {
                        //g.FillRectangle(new SolidBrush(Color.White),bounds);
                        g.FillRectangle(brush, new Rectangle(bounds.X, bounds.Y + 1, bounds.Width, bounds.Height - 1));
                    }
                }
                else
                {
                    g.FillRectangle(new SolidBrush(Color.FromArgb(250, 255, 252, 217)),
                                    new Rectangle(bounds.X, bounds.Y + 1, bounds.Width, bounds.Height - 1));
                }

                // 高亮非选中项
                if (mMouseItem == Items[i] && SelectedIndex != i)
                {
                    Color backColor = Color.FromArgb(200, 192, 224, 248);
                    using (SolidBrush brush = new SolidBrush(backColor))
                    {
                        //g.FillRectangle(new SolidBrush(Color.White),bounds);
                        g.FillRectangle(brush, new Rectangle(bounds.X, bounds.Y + 1, bounds.Width, bounds.Height - 1));
                    }
                }

                // 绘制表项内容
                // 行1
                g.DrawString("教程名称:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 5, bounds.Top + 3);
                g.DrawString("教程类别:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 250, bounds.Top + 3);
                g.DrawString("教程级别:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 400, bounds.Top + 3);

                g.DrawString(item.CourseName, new Font("微软雅黑", 9, FontStyle.Bold), Brushes.Indigo, bounds.Left + 65, bounds.Top + 3);

                // 判断教程标识,转换不同类别
                string configPath = Application.StartupPath + "\\Config\\Config.ini";
                string planType   = IniOperation.ReadValue(configPath, "coursetype", item.CourseType);
                g.DrawString(planType, new Font("微软雅黑", 9, FontStyle.Bold), Brushes.Black, bounds.Left + 310, bounds.Top + 3);

                // 判断教程级别,指定不同颜色
                Brush  levelBrush = Brushes.Black;
                string planLevel  = string.Empty;
                switch (item.CourseLevel)
                {
                case "1":
                    planLevel  = "基础";
                    levelBrush = Brushes.Black;
                    break;

                case "2":
                    planLevel  = "中级";
                    levelBrush = Brushes.BlueViolet;
                    break;

                case "3":
                    planLevel  = "高级";
                    levelBrush = Brushes.MidnightBlue;
                    break;

                case "4":
                    planLevel  = "大师";
                    levelBrush = Brushes.Red;
                    break;

                case "5":
                    planLevel  = "骨灰";
                    levelBrush = Brushes.Purple;
                    break;
                }
                g.DrawString(planLevel, new Font("微软雅黑", 9, FontStyle.Bold), levelBrush, bounds.Left + 460, bounds.Top + 3);
                // 行2
                g.DrawString("起始日期:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 5, bounds.Top + 24);
                g.DrawString("最近学习时间:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 180, bounds.Top + 24);

                g.DrawString(item.StartDate, new Font("微软雅黑", 9, FontStyle.Bold), Brushes.Black, bounds.Left + 65, bounds.Top + 24);
                g.DrawString(item.LastestStudy, new Font("微软雅黑", 9, FontStyle.Bold), Brushes.Black, bounds.Left + 265, bounds.Top + 24);

                // 行3
                //计算学习进度百分比
                string[] info     = item.RelatedResIDs.Split('-');
                double   progress = item.StudyProgress / Convert.ToDouble(info[0]);
                if (progress == 0)
                {
                    progress = 0.01;
                }
                g.DrawString("教程学习进度:", new Font("微软雅黑", 9), Brushes.Black, bounds.Left + 5, bounds.Top + 45);
                g.DrawImage(new Bitmap(Resources.timeprogressbg, new Size(200, 18)),
                            new Point(bounds.Left + 95, bounds.Top + 44));
                g.DrawImage(new Bitmap(Resources.time_progress_fg_lightGreen, new Size((int)(200 * progress), 18)),
                            new Point(bounds.Left + 95, bounds.Top + 44));
                g.DrawString("取消订阅教程", new Font("微软雅黑", 9), Brushes.Blue, bounds.Left + 330, bounds.Top + 45);

                // 判断按钮状态
                // 按下态
                if (buttonDownIndex == i)
                {
                    g.DrawImage(Resources.btn_big_down,
                                new Rectangle(new Point(bounds.Left + 445, bounds.Top + 27), new Size(100, 30)));
                    g.DrawString("开始学习", new Font("微软雅黑", 10), Brushes.DarkGreen, bounds.Left + 467, bounds.Top + 32);
                }
                else
                {
                    // 高亮态
                    if (buttonHighlightIndex == i)
                    {
                        g.DrawImage(Resources.btn_big_hover,
                                    new Rectangle(new Point(bounds.Left + 445, bounds.Top + 27), new Size(100, 30)));
                    }
                    else
                    {
                        g.DrawImage(Resources.btn_big_normal,
                                    new Rectangle(new Point(bounds.Left + 445, bounds.Top + 27), new Size(100, 30)));
                    }
                    g.DrawString("开始学习", new Font("微软雅黑", 10), Brushes.DarkGreen, bounds.Left + 466, bounds.Top + 31);
                }

                g.DrawLine(p, new Point(0, bounds.Top + 65), new Point(Width, bounds.Top + 65));
                p.Dispose();
            }
            //base.OnPaint(e);
        }
 public void Remove(StudyPlanListBoxItem item)
 {
     Owner.OldItems.Remove(item);
 }
 public int IndexOf(StudyPlanListBoxItem item)
 {
     return(Owner.OldItems.IndexOf(item));
 }
 public bool Contains(StudyPlanListBoxItem item)
 {
     return(Owner.OldItems.Contains(item));
 }
 /// <summary>
 /// 选中项被改变事件
 /// </summary>
 /// <param name="e"></param>
 protected override void OnSelectedIndexChanged(EventArgs e)
 {
     mMouseItem = Items[SelectedIndex];
     Invalidate();
     base.OnSelectedIndexChanged(e);
 }
        /// <summary>
        /// 引发 MouseMove 事件
        /// </summary>
        /// <param name="e">包含事件数据的 MouseEventArgs</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            bool      isChange = false; // 指示是否改变
            Rectangle bounds;

            // 轮询表项
            for (int i = 0; i < Items.Count; i++)
            {
                bounds = GetItemRectangle(i);
                if (bounds.Contains(e.X, e.Y))
                {
                    if (e.X > 445 && e.X < 545 && e.Y > (27 + bounds.Y) && e.Y < (57 + bounds.Y))
                    {
                        if (buttonHighlightIndex != i)
                        {
                            buttonHighlightIndex = i;
                            isChange             = true;
                        }
                    }
                    else if (e.X > 330 && e.X < 410 && e.Y > (45 + bounds.Y) && e.Y < (64 + bounds.Y))
                    {
                        buttonDownIndex = -1;
                        if (Cursor != Cursors.Hand)
                        {
                            Cursor = Cursors.Hand;
                            if (Items[i] != mMouseItem)
                            {
                                mMouseItem = Items[i];
                            }
                            break;
                        }
                    }
                    else
                    {
                        buttonDownIndex = -1;
                        if (Cursor != Cursors.Arrow)
                        {
                            Cursor = Cursors.Arrow;
                        }

                        if (buttonHighlightIndex == i)
                        {
                            buttonHighlightIndex = -1;
                            isChange             = true;
                        }
                    }

                    if (Items[i] != mMouseItem)
                    {
                        mMouseItem = Items[i];
                        isChange   = true;
                    }
                }

                if (isChange)
                {
                    break;
                }
            }

            // 判断鼠标指针是否悬浮在空白区域
            if (Items.Count > 0)
            {
                bounds = GetItemRectangle(Items.Count - 1);
                if (e.Y > (65 + bounds.Y))
                {
                    if (Cursor != Cursors.Arrow)
                    {
                        Cursor = Cursors.Arrow;
                    }
                }

                if (isChange)
                {
                    Invalidate();
                }
            }
            base.OnMouseMove(e);
        }