ForumKalbi.Com

ForumKalbi.Com (https://www.forumkalbi.com/index.php)
-   Bilgisayar (https://www.forumkalbi.com/forumdisplay.php?f=220)
-   -   C# Konsol Ekranında Renkli Yazı (https://www.forumkalbi.com/showthread.php?t=4654)

Candres 27 Ocak 2024 18:58

C# Konsol Ekranında Renkli Yazı
 
C# Konsol Ekranında Renkli Yazı
Konsol uygulamasındaki metni kernel32.dll yardımıyla renklendiren program örneği


Kod:

using System;
using System.Runtime.InteropServices;

namespace TextColor1
{
class MainClass
{
[DllImport("kernel32.dll")]
public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput,
int wAttributes);
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(uint nStdHandle);

public static void Main(string[] args)
{
uint STD_OUTPUT_HANDLE = 0xfffffff5;
IntPtr hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// increase k for more color options
for (int k = 1; k < 255; k++)
{
SetConsoleTextAttribute(hConsole, k);
Console.WriteLine("{0:d3} I want to be nice today!",k);
}
// final setting
SetConsoleTextAttribute(hConsole, 236);

Console.WriteLine("Çıkmak için Enter tuşuna basın...");
Console.Read(); // wait
}
}
}


Forum saati; Türkiye'ye göre ayarlanmış olup, şu an saat: 13:02.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Navbar with Avatar by Motorradforum