예제 #1
0
        public Form1()
        {
            InitializeComponent();

            timer_rss.Start();

            for (int i = 0; i < SingleCPUManager.GetCPUCount(); i++)
            {
                SingleCPUList.Add(new SingleCPUManager(i, 200, 4, 30));
            }

            //バージョンの取得
            System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
            System.Version             ver = asm.GetName().Version;
            label_version.Text = $"Assembly Version {ver.ToString()}";

            // 最大化
            this.WindowState = FormWindowState.Maximized;

            // 「埋め込みリソース」から画像を取得
            System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();

            Icon1 = new Bitmap(myAssembly.GetManifestResourceStream(@"SimScreenSaver.img.v2-02.png"));
            Icon2 = new Bitmap(myAssembly.GetManifestResourceStream(@"SimScreenSaver.img.v2-03.png"));
            Icon3 = new Bitmap(myAssembly.GetManifestResourceStream(@"SimScreenSaver.img.v2-04.png"));
            Icon4 = new Bitmap(myAssembly.GetManifestResourceStream(@"SimScreenSaver.img.v2-05.png"));
            Icons = new Bitmap[] { Icon1, Icon2, Icon3, Icon4 };
        }
예제 #2
0
        //==================================================================
        //==================================================================

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Debug.WriteLine($"repaint {DateTime.Now}");

            // -------------- iconを表示
            int duration = 3; // sec
            int index    = (sw.Elapsed.Seconds / duration) % Icons.Length;

            Graphics g = e.Graphics;

            Bitmap icon = this.Icons[index];

            Rectangle IconRect = new Rectangle();

            IconRect.Width  = pictureBox1.Width / 2;
            IconRect.Height = pictureBox1.Height / 2;
            IconRect.X      = (pictureBox1.Width / 2) - (IconRect.Width / 2);
            IconRect.Y      = (pictureBox1.Height / 2) - (IconRect.Height / 2);

            // iconを描画
            // aspect比を合わせる
            if (pictureBox1.Width < pictureBox1.Height)
            {
                // 縦長
                double aspect = (double)icon.Height / icon.Width;
                double h      = aspect * IconRect.Width;

                g.DrawImage(this.Icons[index], IconRect.X, IconRect.Y, IconRect.Width, (int)h);
            }
            else
            {
                // 縦長
                double aspect = (double)icon.Width / icon.Height;
                double w      = aspect * IconRect.Height;
                g.DrawImage(this.Icons[index], IconRect.X, IconRect.Y, (int)w, IconRect.Height);
            }

            // -------------- /iconを表示



            // -------------- CPU使用率を表示

            int[] ave = CPUManager.GetAveValues();
            int[] max = CPUManager.GetMaxValues();
            int[] ptp = CPUManager.GetPeakToPeakValues();



            label_CPU.Text  = "";
            label_CPU.Text += String.Join(", ", ave) + Environment.NewLine;
            label_CPU.Text += String.Join(", ", max) + Environment.NewLine;
            label_CPU.Text += String.Join(", ", ptp) + Environment.NewLine;


            // -------------- CPU使用率を表示

            int Ncpu = Environment.ProcessorCount;

            int W = pictureBox1.Width;
            int H = pictureBox1.Height;

            RectangleF ChartArea = new RectangleF(W * 0.1f, 100, W * 0.8f, (H * 0.1f));

            for (int k = 0; k < Ncpu; k++)
            {
                SingleCPUManager scpu = SingleCPUList[k];

                float[] cpu_values = scpu.GetQueArray();

                int      N       = cpu_values.Length;
                PointF[] Origins = new PointF[N];
                for (int i = 0; i < cpu_values.Length; i++)
                {
                    Origins[i].X = i;
                    Origins[i].Y = cpu_values[i];
                }

                float X0 = ChartArea.X + (ChartArea.Width / Ncpu) * k;
                float Y0 = ChartArea.Y;

                Pen pen = new Pen(Color.Green, 1);

                RectangleF TargetScreen = new RectangleF();
                this.DrawLines(e, pen, Origins,
                               new RectangleF(0, 0, cpu_values.Length * 1.2f, 120),
                               new RectangleF(X0, Y0, ChartArea.Width / Ncpu, ChartArea.Height));
            }
        }