Example #1
0
 public static void TrySetConsoleColor(ConsoleColorFlags colorFlags)
 {
     // SetConsoleTextAttribute may fail if stdout is redirected to a sink other
     // than the cmd window (eg: VS's output window).
     try
     { SetConsoleColor(colorFlags); }
     catch (Win32Exception)
     { }
 }
Example #2
0
 public static void TrySetConsoleColor(ConsoleColorFlags colorFlags)
 {
     // SetConsoleTextAttribute may fail if stdout is redirected to a sink other
     // than the cmd window (eg: VS's output window).
     try
     { SetConsoleColor(colorFlags); }
     catch (Win32Exception)
     { }
 }
Example #3
0
        //
        // Interface
        public static void SetConsoleColor(ConsoleColorFlags colorFlags)
        {
            // Set the color on the current stdout stream.
            const int stdout = -11;

            IntPtr hStdOut = Kernel32.GetStdHandle(stdout);
            if (hStdOut == IntPtr.Zero || hStdOut == new IntPtr(-1))
                throw new Win32Exception();

            if (!Kernel32.SetConsoleTextAttribute(hStdOut, colorFlags))
                throw new Win32Exception();
        }
Example #4
0
    public static void TrySetConsoleColor(ConsoleColorFlags colorFlags)
    {
        // don't do anything if 'black on black'
        if ( 0 == (Int32)colorFlags ) { return; }

        // SetConsoleTextAttribute may fail if stdout is redirected to a sink other
        // than the cmd window (eg: VS's output window).
        try
        { SetConsoleColor(colorFlags); }
        catch (Win32Exception)
        { }
    }
Example #5
0
    public static void TrySetConsoleColor(ConsoleColorFlags colorFlags)
    {
        // don't do anything if 'black on black'
        if (0 == (Int32)colorFlags)
        {
            return;
        }

        // SetConsoleTextAttribute may fail if stdout is redirected to a sink other
        // than the cmd window (eg: VS's output window).
        try
        { SetConsoleColor(colorFlags); }
        catch (Win32Exception)
        { }
    }
Example #6
0
        //
        // Interface

        public static void SetConsoleColor(ConsoleColorFlags colorFlags)
        {
            // Set the color on the current stdout stream.
            const int stdout = -11;

            IntPtr hStdOut = Kernel32.GetStdHandle(stdout);

            if (hStdOut == IntPtr.Zero || hStdOut == new IntPtr(-1))
            {
                throw new Win32Exception();
            }

            if (!Kernel32.SetConsoleTextAttribute(hStdOut, colorFlags))
            {
                throw new Win32Exception();
            }
        }
Example #7
0
 public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, ConsoleColorFlags wAttributes);
Example #8
0
 public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, ConsoleColorFlags wAttributes);