예제 #1
0
        private void DrawGrid(Graphics g)
        {
            float height = g.ClipBounds.Size.Height;
            float stepY  = height / MaxTemp;
            float width  = g.ClipBounds.Size.Width;
            var   pen1   = new Pen(new SolidBrush(Color.FromArgb(128, 128, 128, 128)), 0.5f);
            var   pen2   = new Pen(new SolidBrush(Color.FromArgb(64, 128, 128, 128)), 1f);

            // Draw line every 50 °C
            for (int i = 50; i < MaxTemp; i += 50)
            {
                int level = (int)(height - i * stepY);
                if (i % 100 == 0)
                {
                    g.DrawLine(pen1, 0, level, width, level);
                    g.DrawString(i + "°C", fontSmall, Brushes.LightGray, new Point(2, level - fontSmall.Height));
                }
                else
                {
                    g.DrawLine(pen2, 0, level, width, level);
                }
            }

            // Draw line every 30 minutes
            if (Measurements.Count > 1)
            {
                float duration = (float)(LastRecordTime - Measurements.First().Time).TotalMinutes;
                float stepX    = width / duration;
                for (double i = 30; i < duration; i += 30)
                {
                    g.DrawLine(pen1, (int)(i * stepX), 0, (int)(i * stepX), height);
                    g.DrawString((i / 60.0).ToString("0.#") + "h", fontSmall, Brushes.LightGray, new Point((int)(2 + i * stepX), (int)(height - fontSmall.Height)));
                }
            }
        }