Пример #1
0
        private void RenderProgressBar()
        {
            if (IsInit)
            {
                //validation
                if (ProgressBarValue < 0 || ProgressBarValue > 100)
                {
                    throw new Exception("The value of ProgressBarValue should be greater or equal to 0 and less or equal to 100");
                }

                var g = CreateGraphics();

                var progressBarWidth = (g.Width - 2);

                g.FillRect(1, (short)(g.Height - 1), (short)(g.Width - 2), 1, ConsoleColor.Gray);

                {
                    //background
                    //rect to draw based on ProgressBarValue
                    var progressWidth = (int)((progressBarWidth * ProgressBarValue) / 100);
                    if (progressWidth > 0)
                    {
                        g.FillRect(1, (short)(g.Height - 1), (short)progressWidth, 1, ProgressColor);
                    }
                }

                {
                    //text
                    var progressBarText = ProgressBarText.Substring(0, Math.Min(ProgressBarText.Length, progressBarWidth));
                    var paddingLeft     = (int)((progressBarWidth - progressBarText.Length) / 2);
                    g.DrawText((short)(paddingLeft + 1), (short)(g.Height - 1), progressBarText, _progressTextColor);
                }
            }
        }