I can't get this to work for font names that are 16 characters or longer, but the console itself obviously doesn't have this limitation. Does anyone know a programmatic way to set the font that will work with the built-in "Lucida Sans Typewriter" or the open source "Fira Code Retina"?
This following code works:
I have copied PInvoke code from various places, particularly the PowerShell console host, and the Microsoft Docs
Note that the relevant docs for CONSOLE_FONT_INFOEX and SetCurrentConsoleFontEx do not talk about this, and the struct defines the font face as a WCHAR field of size 32...
Also note what's not a limitation, but is a restriction from the console dialog, is that the font has to have True Type outlines, and must be genuinely fixed width. Using this API you can chose variable width fonts like "Times New Roman" ...
However, in the API, it has to have less than 16 characters in the name -- which is a restriction the console itself doesn't have, and may be a bug in the API and not my code below 🤔
using System;
using System.Runtime.InteropServices;
public static class ConsoleHelper
{
private const int FixedWidthTrueType = 54;
private const int StandardOutputHandle = -11;
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int nStdHandle);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool SetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref FontInfo ConsoleCurrentFontEx);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern bool GetCurrentConsoleFontEx(IntPtr hConsoleOutput, bool MaximumWindow, ref FontInfo ConsoleCurrentFontEx);
private static readonly IntPtr ConsoleOutputHandle = GetStdHandle(StandardOutputHandle);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct FontInfo
{
internal int cbSize;
internal int FontIndex;
internal short FontWidth;
public short FontSize;
public int FontFamily;
public int FontWeight;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
//[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.wc, SizeConst = 32)]
public string FontName;
}
public static FontInfo[] SetCurrentFont(string font, short fontSize = 0)
{
Console.WriteLine("Set Current Font: " + font);
FontInfo before = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>()
};
if (GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref before))
{
FontInfo set = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>(),
FontIndex = 0,
FontFamily = FixedWidthTrueType,
FontName = font,
FontWeight = 400,
FontSize = fontSize > 0 ? fontSize : before.FontSize
};
// Get some settings from current font.
if (!SetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref set))
{
var ex = Marshal.GetLastWin32Error();
Console.WriteLine("Set error " + ex);
throw new System.ComponentModel.Win32Exception(ex);
}
FontInfo after = new FontInfo
{
cbSize = Marshal.SizeOf<FontInfo>()
};
GetCurrentConsoleFontEx(ConsoleOutputHandle, false, ref after);
return new[] { before, set, after };
}
else
{
var er = Marshal.GetLastWin32Error();
Console.WriteLine("Get error " + er);
throw new System.ComponentModel.Win32Exception(er);
}
}
}
You can play with it in a PowerShell window by using Add-Type with that code, and then doing something like this:
[ConsoleHelper]::SetCurrentFont("Consolas", 16)
[ConsoleHelper]::SetCurrentFont("Lucida Console", 12)
Then, use your console "Properties" dialog and manually switch to Lucida Sans Typewriter ... and try just changing the font size, specifying the same font name:
[ConsoleHelper]::SetCurrentFont("Lucida Sans Typewriter", 12)
And you'll get output like this (showing the three settings: before, what we tried, and what we got):
Set Current Font: Lucida Sans Typewriter
FontSize FontFamily FontWeight FontName
-------- ---------- ---------- --------
14 54 400 Lucida Sans Typeʈ
12 54 400 Lucida Sans Typewriter
12 54 400 Courier New
You see that weird character on the end of the "before" value? That's happens whenever the font is longer than 16 characters (I'm getting garbage data because of a problem in the API or the marshalling).
The actual console font name is obviously not length limited, but perhaps it's not possible to use a font with a name that's 16 characters or longer?
For what it's worth, I discovered this problem with Fira Code Retina, a font that has exactly 16 characters in the name -- and I have a little bit more code than what's above in a gist here if you care to experiment...
I had found a bug in the Console API. It's fixed as of Windows 10 (insider) build 18267.
Prior to that release, there wasn't a way around it -- except to use fonts with shorter names, or use the actual window properties panel to set it.
The original post code works now ...
Related
Is there any way to detect which color and which type of windows style windows 10 is running one (the latest one I guess which has light/dark theme - 1903)
I have a tray icon app and would like to display a black/white icon depending on the theme. The built in apps show them properly, but I do not know how to detect it.
You can get current Theme information from the registry :
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes
(the GetCurrentThemeName api returns InstallVisualStyle value on my Windows 10 OS)
Declaration :
[DllImport("UxTheme.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int cchMaxNameChars, StringBuilder pszColorBuff, int cchMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars);
To get the current Theme color (Accent color), you can do :
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#95")]
public static extern int GetImmersiveColorFromColorSetEx(int dwImmersiveColorSet, int dwImmersiveColorType, bool bIgnoreHighContrast, int dwHighContrastCacheMode);
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#96")]
public static extern int GetImmersiveColorTypeFromName(IntPtr pName);
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#98")]
public static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);
int nColorSystemAccent = GetImmersiveColorFromColorSetEx(GetImmersiveUserColorSetPreference(false, false), GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni("ImmersiveSystemAccent")), false, 0);
System.Drawing.Color colorSystemAccent = ColorTranslator.FromWin32(nColorSystemAccent);
// Test color
this.BackColor = colorSystemAccent;
Using c# .net 4.7.1, I'm trying to make a console app Blackjack game and I'm having trouble displaying the card suits to the console output with different versions of Windows. For Windows 7, this is the Main method that displays the suits correctly:
static void Main(string[] args)
{
string[] Suits = new string[] { "♠", "♣", "♥", "♦" };
Methods.Print(Suits[0] + " " + Suits[1] + " " + Suits[2] + " " + Suits[3]);
Console.ReadLine();
....
}
the suits display as I want them, like this:
But if I run my program with this Main method in it on my Windows 10 machine they display like this:
I've found that if I include this line in my Main method on my Windows 10 machine then the suits display as I want them to:
Console.OutputEncoding = System.Text.Encoding.UTF8;
But then that makes it so the suits don't display correctly on my Windows 7 machine. Can anyone help me out with how I can have these card suits display properly regardless of what Windows OS the program is run on? Thanks in advance.
If you want it to work reliably in the console then here is my solution:
static void Main(string[] args)
{
Console.WriteLine("D, C, H, S");
Console.ReadLine();
}
Here are 2 other options:
Check windows versions and test all scenarios using ♠, ♣, ♥, ♦ and Encoding.UTF8;
Gui application.
Windows 7
The problem with Windows7 console and
Console.OutputEncoding = Encoding.UTF8;
Console.WriteLine("♠, ♣, ♥, ♦");
Console.ReadLine();
is most likely the font in console app.
From Console.OutputEncoding Property:
Note that successfully displaying Unicode characters to the console requires the following:
The console must use a TrueType font, such as Lucida Console or Consolas, to display characters.
You can change the font in the Console app's properties:
Thanks to #tymtam for the insight on the issue I'm having. I looked into the possibility of changing the console font as a solution. I found this article that shows how to programmatically change the console font to Lucida Console which is a true type font. Here's my formatted code from that link:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
namespace BlackJack
{
class BlackJack
{
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool SetCurrentConsoleFontEx(IntPtr consoleOutput, bool maximumWindow, ref CONSOLE_FONT_INFO_EX consoleCurrentFontEx);
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int dwType);
[DllImport("kernel32.dll", SetLastError = true)]
static extern int SetConsoleFont(IntPtr hOut, uint dwFontNum);
private const int STD_OUTPUT_HANDLE = -11;
private const int TMPF_TRUETYPE = 4;
private const int LF_FACESIZE = 32;
private static IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal unsafe struct CONSOLE_FONT_INFO_EX
{
internal uint cbSize;
internal uint nFont;
internal COORD dwFontSize;
internal int FontFamily;
internal int FontWeight;
internal fixed char FaceName[LF_FACESIZE];
}
[StructLayout(LayoutKind.Sequential)]
internal struct COORD
{
internal short X;
internal short Y;
internal COORD(short x, short y)
{
X = x;
Y = y;
}
}
public static void SetConsoleFont(string fontName = "Lucida Console")
{
unsafe
{
IntPtr hnd = GetStdHandle(STD_OUTPUT_HANDLE);
if (hnd != INVALID_HANDLE_VALUE)
{
CONSOLE_FONT_INFO_EX info = new CONSOLE_FONT_INFO_EX();
info.cbSize = (uint)Marshal.SizeOf(info);
// Set console font to Lucida Console.
CONSOLE_FONT_INFO_EX newInfo = new CONSOLE_FONT_INFO_EX();
newInfo.cbSize = (uint)Marshal.SizeOf(newInfo);
newInfo.FontFamily = TMPF_TRUETYPE;
IntPtr ptr = new IntPtr(newInfo.FaceName);
Marshal.Copy(fontName.ToCharArray(), 0, ptr, fontName.Length);
// Get some settings from current font.
newInfo.dwFontSize = new COORD(info.dwFontSize.X, info.dwFontSize.Y);
newInfo.FontWeight = info.FontWeight;
SetCurrentConsoleFontEx(hnd, false, ref newInfo);
}
}
}
static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
SetConsoleFont();
....
}
Two things to note
I had to add this using statement for it to work:
using System.Runtime.InteropServices;
I had to check the Allow unsafe code checkbox located in the Project>Properties>Build screen as shown below:
After making these changes the program runs on both Windows 7 and Windows 10 and it displays the card suits as I want them to. Like I said before, I don't have access to machines that have other versions of Windows on them, so I can only say that this runs on Windows 7 and Windows 10 for sure.
I have a rather baffling issue, a program that used to always work now only works once per reboot, when running it again I'm granted with:
Exception thrown: read access violation. this was 0xBF13D000.
I've extended a C++ project with C exports so I can use it from C#:
C exports:
KeyFinder::AudioData* new_audio_data(const unsigned frame_rate, const unsigned channels, const unsigned samples)
{
auto audio_data = new KeyFinder::AudioData();
audio_data->setFrameRate(frame_rate);
audio_data->setChannels(channels);
audio_data->addToSampleCount(samples);
return audio_data;
}
void audio_data_set_sample(KeyFinder::AudioData* audio_data, const unsigned index, const double value)
{
audio_data->setSample(index, value);
}
void keyfinder_progressive_chromagram(KeyFinder::KeyFinder* key_finder, KeyFinder::AudioData* audio_data, KeyFinder::Workspace* workspace)
{
key_finder->progressiveChromagram(*audio_data, *workspace);
}
KeyFinder::key_t keyfinder_key_of_chromagram(KeyFinder::KeyFinder* key_finder, KeyFinder::Workspace* workspace)
{
return key_finder->keyOfChromagram(*workspace);
}
enum key_t {
A_MAJOR = 0,
A_MINOR,
B_FLAT_MAJOR,
B_FLAT_MINOR,
B_MAJOR,
B_MINOR = 5,
C_MAJOR,
C_MINOR,
D_FLAT_MAJOR,
D_FLAT_MINOR,
D_MAJOR = 10,
D_MINOR,
E_FLAT_MAJOR,
E_FLAT_MINOR,
E_MAJOR,
E_MINOR = 15,
F_MAJOR,
F_MINOR,
G_FLAT_MAJOR,
G_FLAT_MINOR,
G_MAJOR = 20,
G_MINOR,
A_FLAT_MAJOR,
A_FLAT_MINOR,
SILENCE = 24
};
C# declarations:
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr new_audio_data(
uint frameRate, uint channels, uint samples);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern void audio_data_set_sample(
IntPtr audioData, uint index, double value);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern void keyfinder_progressive_chromagram(IntPtr keyFinder, IntPtr audioData, IntPtr workspace);
[DllImport("libKeyFinder", CallingConvention = CallingConvention.Cdecl)]
private static extern Key keyfinder_key_of_chromagram(IntPtr keyFinder, IntPtr workspace);
public enum Key
{
AMajor = 0,
AMinor,
BFlatMajor,
BFlatMinor,
BMajor,
BMinor = 5,
CMajor,
CMinor,
DFlatMajor,
DFlatMinor,
DMajor = 10,
DMinor,
EFlatMajor,
EFlatMinor,
EMajor,
EMinor = 15,
FMajor,
FMinor,
GFlatMajor,
GFlatMinor,
GMajor = 20,
GMinor,
AFlatMajor,
AFlatMinor,
Silence = 24
}
C# usage:
public void SetSample(uint index, double value)
{
audio_data_set_sample(_audioData, index, value);
}
What is really puzzling is that when I debug it, the seemingly disposed/destroyed pointer is already visible in the C# part: SetSample._audioData. Initially, when new_audio_data is called from C# I get a valid pointer like 0x032fe940 but for some reason it becomes 0xBF13D000. Note that it always become the value 0xBF13D000 so I've searched about such value online in a hope to spot a known memory pattern but without success.
As I said, there hasn't been any changes to the program, so I'm at a total loss as on what could be causing this.
Try add volatile for _audioData
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/volatile
It turned out that some of the native libraries needed to be all rebuilt using the same compiler version, now it works flawlessly !
I want to get user-friendly names of sound inputs with this code, but it can give me only first 32 chars of name, but I want it whole.
[DllImport("winmm.dll", SetLastError = true)]
static extern uint waveInGetNumDevs();
[DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern uint waveInGetDevCaps(uint hwo, ref WAVEOUTCAPS pwoc, uint cbwoc);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WAVEOUTCAPS
{
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szPname;
public uint dwFormats;
public ushort wChannels;
public ushort wReserved1;
public uint dwSupport;
}
public static string[] GetSoundDevices()
{
uint devices = waveInGetNumDevs();
string[] result = new string[devices];
WAVEOUTCAPS caps = new WAVEOUTCAPS();
using (StreamWriter sw = new StreamWriter("appdata/audio/name"))
{
for (uint i = 0; i < devices; i++)
{
waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
result[i] = caps.szPname;
sw.WriteLine(caps.szPname);
}
return result;
}
}
I need this names of sound inputs:
but this code give me only this:
Thank you guys!
You may have to use the management interface:
ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
"SELECT * FROM Win32_SoundDevice");
ManagementObjectCollection objCollection = objSearcher.Get();
foreach (ManagementObject obj in objCollection)
{
foreach (PropertyData property in obj.Properties)
{
Console.Out.WriteLine(String.Format("{0}:{1}", property.Name, property.Value));
}
}
Source: How to enumerate audio out devices in c#
You can use WASAPI to get full name of sound devices. It's only limit is that it is not available in Windows XP or older OS.
You need to use IMMDeviceEnumerator::EnumAudioEndpoints method to achieve the goal, but since the library is COM, you need to wrap it to be able to use it in C#.
A sample project is available on CodeProject.
I also couldn't find a way to get full name using WinMM library and finally end up writing a C++ wrapper around WASAPI and used that wrapper in C# through pinvoke!
Why screenshots in foreign and totally not understandable language?
There you go. English screenshot 1
You can copy it, that is what the second one means.
The number stands for the usb bus that is used.
When changing the plug keep that in mind.
I have a c# .net 3.5 application that writes text to the console using a StreamWriter. Is there a way I can add text decorations like underline and strikethrough to the text that is printed to the console? Possibly using ANSI escape sequences?
TextWriter writer = new StreamWriter(Console.OpenStandardOutput());
writer.WriteLine("some underlined text");
Thanks,
PaulH
In Windows 10 build 16257 and later:
using System;
using System.Runtime.InteropServices;
class Program
{
const int STD_OUTPUT_HANDLE = -11;
const uint ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4;
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
[DllImport("kernel32.dll")]
static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
static void Main()
{
var handle = GetStdHandle(STD_OUTPUT_HANDLE);
uint mode;
GetConsoleMode(handle, out mode);
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(handle, mode);
const string UNDERLINE = "\x1B[4m";
const string RESET = "\x1B[0m";
Console.WriteLine("Some " + UNDERLINE + "underlined" + RESET + " text");
}
}
The Windows console does not support ANSI escape sequences. To my knowledge, the only way to change the attributes of an output character is to call SetConsoleTextAttribute before writing the character. Or, in .NET, modify the Console.ForegroundColor or Console.BackgroundColor attributes.
It might be possible to set those properties to custom values (i.e. values not defined by ConsoleColor) with a type cast. But I don't know what good that would do you.
I don't know that I've ever seen strikethrough text on a Windows console, and it's been years since I saw underline. I suppose it's possible, but I don't know how it's done.
I use this code. It's a fixed version of Vladimir Reshetnikov's answer, using the correct escape code for the reset.
private static void WriteUnderline(string s)
{
var handle = GetStdHandle(STD_OUTPUT_HANDLE);
uint mode;
GetConsoleMode(handle, out mode);
mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
SetConsoleMode(handle, mode);
Console.WriteLine($"\x1B[4m{s}\x1B[24m");
}
This will do underlined text, and has the benefit of not resetting any colors you have set.
Short answer, no; the console doesn't allow the use of underlined characters in output.
Longer answer: The screen buffer used by the console is little more than a byte array. Each cursor position is one byte or one character. To create an underline, you either need two characters overlapping (which isn't possible in the console), or you need access to a codepage that uses the upper 128 character values as underlined or strikethrough versions of the lower 128 (I don't know of one).
You can work around this if you are willing to go "double-spaced" for lines that have underlines. Character code 0x00AF (decimal 175) is a "text art" character representing a border across the top of the character space. If you use those in the line underneath your text, presto, underlines.
I found this question and thought I would add to the answers for pre-windows 10 terminal using kernel32 functions,
using System;
using System.Runtime.InteropServices;
namespace color_console
{
class Class1
{
static void Main(string[] args)
{
Class1 c = new Class1();
c.change();
}
[DllImport("kernel32.dll", SetLastError=true)]
public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, CharacterAttributes wAttributes);
[DllImport("kernel32.dll")]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll")]
public static extern bool GetConsoleScreenBufferInfo(IntPtr hConsoleOutput,
ref CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
void change()
{
const int STD_OUTPUT_HANDLE = -11;
IntPtr hOut;
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo = new CONSOLE_SCREEN_BUFFER_INFO();
GetConsoleScreenBufferInfo(hOut, ref ConsoleInfo);
CharacterAttributes originalAttributes = (CharacterAttributes)ConsoleInfo.wAttributes;
//write some text
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_BLUE);
Console.WriteLine("Blue text");
SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_RED);
Console.WriteLine("Red background");
SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_GREEN);
Console.WriteLine("Green background");
SetConsoleTextAttribute(hOut, CharacterAttributes.BACKGROUND_GREEN | CharacterAttributes.BACKGROUND_RED);
Console.WriteLine("Yellow background");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_RED | CharacterAttributes.COMMON_LVB_UNDERSCORE);
Console.WriteLine("Red underlined text");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_RED
| CharacterAttributes.FOREGROUND_BLUE);
Console.WriteLine("Purple text");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_RED
| CharacterAttributes.FOREGROUND_BLUE
| CharacterAttributes.FOREGROUND_INTENSITY);
Console.WriteLine("Purple text intense");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_GREEN
| CharacterAttributes.FOREGROUND_BLUE
| CharacterAttributes.COMMON_LVB_REVERSE_VIDEO);
Console.WriteLine("Aqua reversed text ");
SetConsoleTextAttribute(hOut, CharacterAttributes.FOREGROUND_GREEN
| CharacterAttributes.FOREGROUND_BLUE
| CharacterAttributes.COMMON_LVB_REVERSE_VIDEO
| CharacterAttributes.FOREGROUND_INTENSITY);
Console.WriteLine("Aqua reversed intense text ");
SetConsoleTextAttribute(hOut, CharacterAttributes.COMMON_LVB_GRID_LVERTICAL
| CharacterAttributes.FOREGROUND_GREEN);
Console.WriteLine("What does this do");
SetConsoleTextAttribute(hOut, originalAttributes);
Console.WriteLine("Back to the shire");
}
public enum CharacterAttributes
{
FOREGROUND_BLUE = 0x0001,
FOREGROUND_GREEN = 0x0002,
FOREGROUND_RED = 0x0004,
FOREGROUND_INTENSITY = 0x0008,
BACKGROUND_BLUE = 0x0010,
BACKGROUND_GREEN = 0x0020,
BACKGROUND_RED = 0x0040,
BACKGROUND_INTENSITY = 0x0080,
COMMON_LVB_LEADING_BYTE = 0x0100,
COMMON_LVB_TRAILING_BYTE = 0x0200,
COMMON_LVB_GRID_HORIZONTAL = 0x0400,
COMMON_LVB_GRID_LVERTICAL = 0x0800,
COMMON_LVB_GRID_RVERTICAL = 0x1000,
COMMON_LVB_REVERSE_VIDEO = 0x4000,
COMMON_LVB_UNDERSCORE = 0x8000
}
[StructLayout(LayoutKind.Sequential)]
public struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public int wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}
// Standard structures used for interop with kernel32
[StructLayout(LayoutKind.Sequential)]
public struct COORD
{
public short x;
public short y;
}
[StructLayout(LayoutKind.Sequential)]
public struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}
}
}
Output on my PC
It's pretty easy to change the foreground/background color of console : http://www.dotnetperls.com/console-color but AFAIK there is no way to put some bold text, for example. But I didn't really tried to achieve that so i'm not sure.