- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
- [C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
[C#] Chia sẻ class Bootstrap format style trên console winform
Xin chào các bạn, bài viết hôm nay mình chia sẻ các bạn class BootStrap Style để xuất định dạng chữ trên Console Winform.
[C#] Bootstrap Style in Console windows
Dưới đây là hình ảnh demo ứng dụng:
Đầu tiên, các bạn tạo mình 1 class Bootstrap.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BootstrapStyle
{
public static class Bootstrap
{
//Bootstrap.Write Basic
public static void Write(string style, string value)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Console.Write(value);
Console.ResetColor();
}
public static void Write(string value, int min, int max)
{
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
}
public static void Write(string style, string value, int min, int max)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
Console.ResetColor();
}
//Bootstrap.Write with params
public static void Write(string style, string value, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Console.Write(value, arg);
Console.ResetColor();
}
public static void Write(string value, int min, int max, params object[] arg)
{
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
}
public static void Write(string style, string value, int min, int max, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
Console.ResetColor();
}
//Bootstrap.WriteLine Basic
public static void WriteLine(string style, string value)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Console.WriteLine(value);
Console.ResetColor();
}
public static void WriteLine(string value, int min, int max)
{
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
}
public static void WriteLine(string style, string value, int min, int max)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
Console.ResetColor();
}
//Bootstrap.WriteLine with params
public static void WriteLine(string style, string value, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Console.WriteLine(value, arg);
Console.ResetColor();
}
public static void WriteLine(string value, int min, int max, params object[] arg)
{
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
}
public static void WriteLine(string style, string value, int min, int max, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
break;
}
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
Console.ResetColor();
}
//Bootstrap.Alert Basic
public static void Alert(string style, string value)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Console.Write(value);
Console.ResetColor();
}
public static void Alert(string style, string value, int min, int max)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
Console.ResetColor();
}
//Bootstrap.Alert with params
public static void Alert(string style, string value, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Console.Write(value, arg);
Console.ResetColor();
}
public static void Alert(string style, string value, int min, int max, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
Console.Write(value.Substring(t, 1));
}
Console.ResetColor();
}
//Bootstrap.AlertLineBasic
public static void AlertLine(string style, string value)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Console.WriteLine(value);
Console.ResetColor();
}
public static void AlertLine(string style, string value, int min, int max)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Random speed = new Random();
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
Console.ResetColor();
}
//Bootstrap.AlertLine with params
public static void AlertLine(string style, string value, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Console.WriteLine(value, arg);
Console.ResetColor();
}
public static void AlertLine(string style, string value, int min, int max, params object[] arg)
{
switch (style)
{
case "Success":
Console.ForegroundColor = ConsoleColor.Green;
Console.BackgroundColor = ConsoleColor.DarkGreen;
break;
case "Information":
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkCyan;
break;
case "Warning":
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.DarkYellow;
break;
case "Danger":
Console.ForegroundColor = ConsoleColor.Red;
Console.BackgroundColor = ConsoleColor.DarkRed;
break;
default:
Console.ForegroundColor = ConsoleColor.Gray;
Console.BackgroundColor = ConsoleColor.DarkGray;
break;
}
Random speed = new Random();
value = string.Format(value, arg);
for (int t = 0; t < value.Count(); t++)
{
Thread.Sleep(Convert.ToInt32(speed.Next(min, max)));
if (t != value.Count() - 1)
{
Console.Write(value.Substring(t, 1));
}
else
{
Console.WriteLine(value.Substring(t, 1));
}
}
Console.ResetColor();
}
}
}
Các bạn đọc code sẽ thấy thường mình xuất thông báo theo 4 loại: Success, Warning, Infomation, Danger và Default.
Các sử dụng:
namespace BootstrapStyle
{
internal class Program
{
static void Main(string[] args)
{
Bootstrap.WriteLine("Success", "Bootstrap Style Console");
Bootstrap.WriteLine("Danger", "Bootstrap Style Console");
Bootstrap.WriteLine("Warning", "Bootstrap Style Console");
Bootstrap.WriteLine("Infomation", "Bootstrap Style Console");
Bootstrap.Alert("Success", "Bootstrap Style Console");
Bootstrap.AlertLine("Danger", "Hello laptrinhvb.net", 10, 20);
Console.ReadKey();
}
}
}
Nếu các bạn truyền vào thông số thời gian, chữ sẽ chạy effect dạng label text.
Thanks for watching!