- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[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 :)