private void DigitalGauge_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            SevenSegmentHelper sevenSegmentHelper = new SevenSegmentHelper(e.Graphics);

            SizeF digitSizeF = sevenSegmentHelper.GetStringSize(_digitText, Font);
            float scaleFactor = Math.Min(ClientSize.Width / digitSizeF.Width, ClientSize.Height / digitSizeF.Height);
            Font font = new Font(Font.FontFamily, scaleFactor * Font.SizeInPoints);
            digitSizeF = sevenSegmentHelper.GetStringSize(_digitText, font);

            using (SolidBrush brush = new SolidBrush(_digitColor))
            {
                using (SolidBrush lightBrush = new SolidBrush(Color.FromArgb(20, _digitColor)))
                {
                    sevenSegmentHelper.DrawDigits(
                        _digitText, font, brush, lightBrush,
                        (ClientSize.Width - digitSizeF.Width) / 2,
                        (ClientSize.Height - digitSizeF.Height) / 2);
                }
            }
        }
Пример #2
0
        private void DigitalGauge_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            SevenSegmentHelper sevenSegmentHelper = new SevenSegmentHelper(e.Graphics);

            SizeF digitSizeF  = sevenSegmentHelper.GetStringSize(_digitText, Font);
            float scaleFactor = Math.Min(ClientSize.Width / digitSizeF.Width, ClientSize.Height / digitSizeF.Height);
            Font  font        = new Font(Font.FontFamily, scaleFactor * Font.SizeInPoints);

            digitSizeF = sevenSegmentHelper.GetStringSize(_digitText, font);

            using (SolidBrush brush = new SolidBrush(_digitColor))
            {
                using (SolidBrush lightBrush = new SolidBrush(Color.FromArgb(20, _digitColor)))
                {
                    sevenSegmentHelper.DrawDigits(
                        _digitText, font, brush, lightBrush,
                        (ClientSize.Width - digitSizeF.Width) / 2,
                        (ClientSize.Height - digitSizeF.Height) / 2);
                }
            }
        }