private void RenderProgressBar(ProgressBar progressBar) { var location = progressBar.AbsoluteLocation(); ConsoleAdapter.MoveCursor(location.Left, location.Top); ConsoleAdapter.Write(new string(' ', progressBar.Width)); int normalMax = progressBar.Maximum - progressBar.Minimum; int normalValue = progressBar.Value - progressBar.Minimum; var size = (int)((normalValue / (normalMax * 1.0)) * progressBar.Width); ConsoleAdapter.MoveCursor(location.Left, location.Top); ConsoleColor saveColor = ConsoleAdapter.BackgroundColor; ConsoleAdapter.BackgroundColor = progressBar.StripeColor; ConsoleAdapter.Write(new string(' ', size)); ConsoleAdapter.BackgroundColor = saveColor; if (progressBar.DisplayText) { int titleLength = progressBar.VisibleText.Length; int left = 0; int offset = 0; switch (progressBar.TextAligment) { case TitleAligment.Left: left = location.Left; offset = 0; break; case TitleAligment.Center: offset = (progressBar.Width / 2) - (titleLength / 2); left = offset + location.Left; break; case TitleAligment.Right: offset = progressBar.Width - titleLength; left = offset + location.Left; break; default: throw new ArgumentOutOfRangeException("aligment"); } ConsoleAdapter.MoveCursor(location.Left, location.Top); var intersection = size - offset < 0 ? 0 : size - offset; var filledString = progressBar.VisibleText.Substring(0, intersection > progressBar.VisibleText.Length ? progressBar.VisibleText.Length : intersection); var nonFilledString = progressBar.VisibleText.Substring(intersection > progressBar.VisibleText.Length ? progressBar.VisibleText.Length : intersection); ConsoleAdapter.BackgroundColor = progressBar.StripeColor; ConsoleAdapter.ForegroundColor = progressBar.BackgroundColor; ConsoleAdapter.MoveCursor(left, location.Top); ConsoleAdapter.Write(filledString); if (!string.IsNullOrEmpty(nonFilledString)) { ConsoleAdapter.BackgroundColor = progressBar.BackgroundColor; ConsoleAdapter.ForegroundColor = progressBar.StripeColor; ConsoleAdapter.MoveCursor(left + filledString.Length, location.Top); ConsoleAdapter.Write(nonFilledString); } } }