Exemple #1
0
        // 加载本地设置
        private void LoadLocalSetting()
        {
            // 测试目录
            string testDir = IniOperation.ReadValue(FrmMain.APP_CFG_PATH, "cache", "test_filter_dir");

            if (testDir.Length > 0 && Directory.Exists(testDir))
            {
                ((CharmTextBox)mControls[0]).Text = testDir;
            }
        }
        /// <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);
        }