Ejemplo n.º 1
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                metroPieChart1.Segments.Clear();
                currentProcesses.Clear();
                currentLabels.Clear();
                List <Label> LabelsToRemove = new List <Label>();
                foreach (Control item in tabPage1.Controls)
                {
                    if (item.GetType() == typeof(Label))
                    {
                        LabelsToRemove.Add((Label)item);
                    }

                    foreach (var label in LabelsToRemove)
                    {
                        this.tabPage1.Controls.Remove(label);
                        label.Dispose();
                    }
                }
                string[] text = File.ReadAllLines(ChartHistoryPath + "\\" + comboBox1.SelectedItem + ".txt");
                foreach (string line in text)
                {
                    string[] aux = line.Split('|');
                    MetroSuite.MetroPieChartSegment seg = new MetroSuite.MetroPieChartSegment();
                    seg.Name      = aux[0];
                    seg.FillColor = ColorTranslator.FromHtml(aux[1]);

                    seg.Value = int.Parse(aux[3]);
                    metroPieChart1.Segments.Add(seg);

                    Label l = new Label();
                    l.BackColor = ColorTranslator.FromHtml(aux[1]);
                    l.Text      = FormatProcess(aux[0]);
                    l.TextAlign = ContentAlignment.MiddleCenter;
                    l.ForeColor = ColorTranslator.FromHtml(aux[2]);
                    currentLabels.Add(l);
                    tabPage1.Controls.Add(l);

                    int labelX, labelY;
                    for (int i = 0; i < currentLabels.Count; i++)
                    {
                        labelX = (i) % (tabPage1.Width / currentLabels[i].Width - 0) * currentLabels[i].Width + currentLabels[i].Width / 2;

                        labelY = tabPage1.Height - currentLabels[i].Height - 20 - (i - 1) / (tabPage1.Width / currentLabels[i].Width - 1) * currentLabels[i].Height;

                        currentLabels[i].Location = new Point(labelX, labelY);

                        //toolTip1.SetToolTip(currentLabels[i], processes[i].Minutes.ToString("HH:mm:ss"));
                    }
                }
            }
            catch { }
        }
Ejemplo n.º 2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            string s      = GetForegroundProcessName();
            bool   exists = false;
            Random r      = new Random();



            foreach (Process p in processes)
            {
                if (p.compareTo(s))
                {
                    exists     = true;
                    p.Minutes += DateTime.Now - time;

                    break;
                }
            }

            if (!exists)
            {
                Process p = new Process(s);
                processes.Add(p);

                Label l = new Label();
                l.BackColor = p.Color;
                l.Text      = FormatProcess(p.Name);
                l.TextAlign = ContentAlignment.MiddleCenter;
                l.ForeColor = p.fontColor;
                labels.Add(l);
                tabPage1.Controls.Add(l);
            }

            if (comboBox1.Text == startDate.ToLongDateString())
            {
                metroPieChart1.Segments.Clear();
                foreach (Process p in processes)
                {
                    MetroSuite.MetroPieChartSegment seg = new MetroSuite.MetroPieChartSegment();
                    seg.Name      = p.Name;
                    seg.FillColor = p.Color;
                    seg.Value     = (int)TimeSpan.FromTicks(p.Minutes.Ticks).TotalMilliseconds;
                    metroPieChart1.Segments.Add(seg);
                }
                toolTip1.SetToolTip(metroPieChart1, "System Uptime: " + GetUpTime().ToString().Remove(GetUpTime().ToString().Length - 8));


                int labelX, labelY;
                for (int i = 0; i < labels.Count; i++)
                {
                    labelX = (i) % (tabPage1.Width / labels[i].Width - 0) * labels[i].Width + labels[i].Width / 2;

                    labelY = tabPage1.Height - labels[i].Height - 20 - (i - 1) / (tabPage1.Width / labels[i].Width - 1) * labels[i].Height;

                    labels[i].Location = new Point(labelX, labelY);

                    toolTip1.SetToolTip(labels[i], processes[i].Minutes.ToString("HH:mm:ss"));
                }
            }


            time = DateTime.Now;
        }