예제 #1
0
        /// <summary>
        /// 添加当前活动窗口
        /// </summary>
        /// <param name="process"></param>
        public void AddViewItem(IWindow window)
        {
            AppSmallIconList.Images.Add(window.AppIcon);
            AppList.BeginUpdate();
            ListViewItem item = new ListViewItem(window.WindowTitle);

            item.Tag        = window;
            item.ImageIndex = AppSmallIconList.Images.Count - 1;
            item.SubItems.Add("");
            item.SubItems.Add(window.ForegroundTimeSpen.ToString(@"hh\:mm\:ss"));
            AppList.Items.Add(item);

            // 添加进度条
            Rectangle rectangle = default(Rectangle);

            rectangle = item.SubItems[1].Bounds;
            IProgressBar progressBar = new IProgressBar(rectangle)
            {
                Value   = 0,
                Visible = true,
                Maximum = 100
            };

            item.SubItems[1].Tag = progressBar;
            progressBar.Parent   = AppList;
            AppList.EndUpdate();
        }
예제 #2
0
        /// <summary>
        /// 更新窗口视图
        /// </summary>
        public void UpdateView()
        {
            // 更新FormStatus内容
            OSRunTImeLabel.Text = OSRunTime.ToString(@"%h'hou. '%m'min. '%s'sec.'");
            OSUseTimeLabel.Text = IWindowManager.OSUseTime.ToString(@"%h'hou. '%m'min. '%s'sec.'");

            AppList.BeginUpdate();
            foreach (ListViewItem item in AppList.Items)
            {
                IWindow window = (IWindow)item.Tag;
                item.SubItems[2].Text = window.ForegroundTimeSpen.ToString(@"%h'h. '%m'm. '%s's.'");
            }

            AppList.Sort();

            foreach (ListViewItem item in AppList.Items)
            {
                IWindow window = (IWindow)item.Tag;

                if (window.ForegroundTimeSpen > IWindowManager.OSUseTime)
                {
                    Console.WriteLine("错误:应用时间大于系统使用时间");
                    return;
                }
                Rectangle rectangle = item.SubItems[1].Bounds;
                ((IProgressBar)item.SubItems[1].Tag).SetBounds(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                if (IWindowManager.OSUseTime == TimeSpan.Zero)
                {
                    ((IProgressBar)item.SubItems[1].Tag).Value = 0;
                }
                else
                {
                    ((IProgressBar)item.SubItems[1].Tag).Value = (int)(window.ForegroundTimeSpen.TotalSeconds * 100 / IWindowManager.OSUseTime.TotalSeconds);
                }
            }
            AppList.EndUpdate();
        }