Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# hex to console color

public static ConsoleColor FromHex(string hex)
    {
        int argb = Int32.Parse(hex.Replace("#", ""), NumberStyles.HexNumber);
        Color c = Color.FromArgb(argb);
        
        int index = (c.R > 128 | c.G > 128 | c.B > 128) ? 8 : 0; // Bright bit
        index |= (c.R > 64) ? 4 : 0; // Red bit
        index |= (c.G > 64) ? 2 : 0; // Green bit
        index |= (c.B > 64) ? 1 : 0; // Blue bit
        
        return (System.ConsoleColor)index;
    }
Comment

c# color to console color

 public static ConsoleColor FromColor(Color c)
        {
            int index = (c.R > 128 | c.G > 128 | c.B > 128) ? 8 : 0; // Bright bit
            index |= (c.R > 64) ? 4 : 0; // Red bit
            index |= (c.G > 64) ? 2 : 0; // Green bit
            index |= (c.B > 64) ? 1 : 0; // Blue bit

            return (System.ConsoleColor)index;
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# random generator 
Csharp :: c# stop loop 
Csharp :: select a object from list based on a value csharp 
Csharp :: c# pick a random item from array 
Csharp :: void update 
Csharp :: c# date 
Csharp :: c# append textbox 
Csharp :: C# .net core convert to int round up 
Csharp :: how to get key value from json object in c# 
Csharp :: update models with ef core 
Csharp :: unity animator check if animation is playing 
Csharp :: c# afficher texte 
Csharp :: tostring tmpro unity 
Csharp :: shuffle arraylist c# 
Csharp :: merge sort in c# 
Csharp :: unity create a child object 
Csharp :: if unity 
Csharp :: swaggergen add service not getting info in .net core 
Csharp :: unity assembly 
Csharp :: accessing form controls from another class c# 
Csharp :: cannot convert string to generic type c# 
Csharp :: instantiate list c# 
Csharp :: c# get command line arguments 
Csharp :: c# initialize empty array 
Csharp :: .net c# print object 
Csharp :: system.io.directorynotfoundexception c# 
Csharp :: c# cast to int 
Csharp :: Install Mono project on Ubuntu 20.04 
Csharp :: check shell command success 
Csharp :: how to pass string value to enum in c# 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =