Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# Console Font

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;

namespace ConsoleExtender {
    [StructLayout(LayoutKind.Sequential, Pack = 1)]
    public struct ConsoleFont {
        public uint Index;
        public short SizeX, SizeY;
    }

    public static class ConsoleHelper {
        [DllImport("kernel32")]
        public static extern bool SetConsoleIcon(IntPtr hIcon);

        public static bool SetConsoleIcon(Icon icon) {
            return SetConsoleIcon(icon.Handle);
        }

        [DllImport("kernel32")]
        private extern static bool SetConsoleFont(IntPtr hOutput, uint index);

        private enum StdHandle {
            OutputHandle = -11
        }

        [DllImport("kernel32")]
        private static extern IntPtr GetStdHandle(StdHandle index);

        public static bool SetConsoleFont(uint index) {
            return SetConsoleFont(GetStdHandle(StdHandle.OutputHandle), index);
        }

        [DllImport("kernel32")]
        private static extern bool GetConsoleFontInfo(IntPtr hOutput, [MarshalAs(UnmanagedType.Bool)]bool bMaximize, 
            uint count, [MarshalAs(UnmanagedType.LPArray), Out] ConsoleFont[] fonts);

        [DllImport("kernel32")]
        private static extern uint GetNumberOfConsoleFonts();

        public static uint ConsoleFontsCount {
            get {
                return GetNumberOfConsoleFonts();
            }
        }

        public static ConsoleFont[] ConsoleFonts {
            get {
                ConsoleFont[] fonts = new ConsoleFont[GetNumberOfConsoleFonts()];
                if(fonts.Length > 0)
                    GetConsoleFontInfo(GetStdHandle(StdHandle.OutputHandle), false, (uint)fonts.Length, fonts);
                return fonts;
            }
        }

    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: How to execute script in C# 
Csharp :: linq select 
Csharp :: HttpClient .net Core add Certificate 
Csharp :: messagebox yes no c# 
Csharp :: serialize object to json 
Csharp :: c# multiple exceptions same handler 
Csharp :: static initializer 
Csharp :: how to add arrays in c# 
Csharp :: c# how to initialize an array 
Csharp :: c# run a scheduled task 
Csharp :: How to create a class and objects in C# 
Csharp :: unity fixedupdate 
Csharp :: what dotnet command does 
Csharp :: bezier_curve 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: jobject alternative in system.text.json 
Csharp :: c# driver.findelement to look for declared variable 
Csharp :: selecteditem treeview wpf 
Csharp :: avoid writing the name of the type twice 
Csharp :: c# Class instance 
Csharp :: clear highlight winforms treeview 
Csharp :: validate preview input number wpf 
Csharp :: entity framework dynamic search solution 1 
Csharp :: c# ushort 
Csharp :: c# insert from with bind array 
Csharp :: tomatch jest 
Csharp :: vb.net delete line from text file 
Csharp :: c# load button image from resource 
Csharp :: opération inter-threads non valide 
Csharp :: Custom Circular Picture Box C# win Form app 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =