- [C#] Hướng dẫn giải nén file *.rar với tiến trình progress bar winform
- [C#] Chia sẻ source code make Crazy Error Message Effect Bomb Windows
- [C#] Lập trình ứng dụng theo mô hình MVP Model-View-Presenter Pattern Winform
- [C#] Giới thiệu và những thứ hay ho từ thư viện System.Reactive của Microsoft
- [C#] Hướng dẫn tạo ứng dụng Chat với GPT sử dụng Open AI API
- [DEVEXPRESS] Tạo month picker trên DateEdit Winform C#
- [DATABASE] Cách sử dụng và lưu ý khi sử dụng khóa ngoại (Foreign Key) trong Sqlserver
- [C#] Garbage Collector (GC) là gì? Cách giải phóng bộ nhớ trên ứng dụng Winform khi các đối tượng không còn sử dụng
- [C#] Cách tính độ tương phản màu sắc Contrast Color mà con người có thể nhìn thấy được
- [C#] Hướng dẫn mã hóa mật khẩu tài khoản ứng dụng đúng chuẩn Men
- [C#] Sử dụng Open AI Chat GPT viết ứng dụng Count down timer có hiệu ứng trên winform
- [DATABASE] Chia sẻ dữ liệu Pantone Color sql và json api
- [SQLSERVER] Tạo mã sản phẩm tự động như: SP0001, SP0002, SP0003... sử dụng Trigger
- [C#] Hướng dẫn kiểm tra phiên bản NET Framework cài đặt ở máy tính
- [C#] Hướng dẫn đọc file excel đơn giản sử dụng thư viện Epplus
- [C#] ConcurrentBag là gì và cách sử dụng nó trong lập trình bất đồng bộ
- [C#] AutoResetEvent là gì và cách sử dụng
- [DEVEXPRESS] Chia sẻ source code cách tạo biểu đồ sơ đồ tổ chức công ty Org Chart trên Winform C#
- [C#] Hướng dẫn tạo Auto Number trên Datagridview winform
- [DATABASE] Hướng dẫn tạo Procedure String Split in Mysql
[C#] Hướng dẫn thay đổi màu chữ Console Application
Bình thường khi các bạn viết các ứng dụng Console Application C# thì giao diện mặc định là nền đen chữ trắng. Bài viết hôm nay, mình sẽ hướng dẫn các bạn cách lập trình thay đổi màu chữ trên màn hình console.
Dưới đây, là hai đoạn code thay đổi màu nền và màu chữ của Console App
ConsoleColor background = Console.BackgroundColor;
ConsoleColor foreground = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Bây giờ, nếu các bạn muốn khôi phục màu chữ và nền gốc, các bạn thực hiện câu lệnh reset bên dưới:
Console.ResetColor();
Dưới đây là giao diện ứng dụng demo thay đổi màu chữ và nền window console C#
Source code C#:
using System;
class ConsoleColorsClass {
static void Main(string[] args) {
// Let's go through all Console colors and set them as foreground
foreach(ConsoleColor color in Enum.GetValues(typeof(ConsoleColor))) {
Console.ForegroundColor = color;
Console.WriteLine($ "Foreground color set to {color}");
}
Console.WriteLine("=====================================");
Console.ForegroundColor = ConsoleColor.White;
// Let's go through all Console colors and set them as background
foreach(ConsoleColor color in Enum.GetValues(typeof(ConsoleColor))) {
Console.BackgroundColor = color;
Console.WriteLine($ "Background color set to {color}");
}
Console.WriteLine("=====================================");
// Restore original colors
Console.ResetColor();
Console.ReadKey();
}
}
HAVE FUN :)