/// <summary> /// Sets the current attribute (foreground and background colors) to be used when /// writing characters. /// </summary> /// <param name="attr">The desired output attribute.</param> public void SetTextAttribute(ConsoleCharAttribute attr) { if (!WinCon.SetConsoleTextAttribute(handle, attr)) { throw new ApplicationException("Unable to set text attribute"); } }
/// <summary> /// Fills character attributes at a given cursor position. /// </summary> /// <param name="fgColor">The foreground color to use in the fill.</param> /// <param name="bgColor">The background color to use in the fill.</param> /// <param name="numAttrs">The number of character cells to be filled with the attribute.</param> /// <param name="x">The column position where the fill operation is to start.</param> /// <param name="y">The row position where the fill operation is to start.</param> /// <returns>The number of character cells in which the attribute was written.</returns> public int FillAttributeXY(ConsoleColor fgColor, ConsoleColor bgColor, int numAttrs, int x, int y) { Coord pos = new Coord((short)x, (short)y); ConsoleCharAttribute attr = new ConsoleCharAttribute(fgColor, bgColor); int attrsWritten = 0; if (!WinCon.FillConsoleOutputAttribute(handle, attr, numAttrs, pos, ref attrsWritten)) { throw new ApplicationException("Error writing attributes"); } return(attrsWritten); }
/// <summary> /// Reads character attributes from the screen buffer, starting at the given position. /// </summary> /// <param name="nattrs">Number of attributes to read.</param> /// <param name="x">Column position of the first attribute to read.</param> /// <param name="y">Row position of the first attribute to read.</param> /// <returns>An array containing the attributes read from the screen buffer.</returns> public ConsoleCharAttribute[] ReadAtrributesXY(int nColors, int x, int y) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } ConsoleCharAttribute[] buff = new ConsoleCharAttribute[nColors]; int colorsRead = 0; if (!WinCon.ReadConsoleOutputAttribute(handle, buff, nColors, new Coord((short)x, (short)y), ref colorsRead)) { throw new System.IO.IOException("Read error", Marshal.GetLastWin32Error()); } if (colorsRead < nColors) { ConsoleCharAttribute[] newBuff = new ConsoleCharAttribute[colorsRead]; Array.Copy(buff, newBuff, colorsRead); return(newBuff); } return(buff); }
/// <summary> /// Resets foreground and background colors to their defaults. /// </summary> public void ResetColor() { ConsoleCharAttribute attr = new ConsoleCharAttribute(ConsoleColor.Gray, ConsoleColor.Black); SetTextAttribute(attr); }
/// <summary> /// Writes character attributes to the screen buffer at the given cursor position. /// </summary> /// <param name="attrs">An array of attributes to be written to the screen buffer.</param> /// <param name="nattrs">The number of attributes to be written.</param> /// <param name="x">Column position in which to write the first attribute.</param> /// <param name="y">Row position in which to write the first attribute.</param> /// <returns>Returns the number of attributes written.</returns> public int WriteAttributesXY(ConsoleCharAttribute[] attrs, int nattrs, int x, int y) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } if (nattrs > attrs.Length) { throw new ArgumentException("nattrs cannot be larger than the array length"); } int attrsWritten = 0; Coord writePos = new Coord((short)x, (short)y); if (!WinCon.WriteConsoleOutputAttribute(handle, attrs, attrs.Length, writePos, ref attrsWritten)) { throw new System.IO.IOException("Write error", Marshal.GetLastWin32Error()); } return attrsWritten; }
/// <summary> /// Reads character attributes from the screen buffer, starting at the given position. /// </summary> /// <param name="nattrs">Number of attributes to read.</param> /// <param name="x">Column position of the first attribute to read.</param> /// <param name="y">Row position of the first attribute to read.</param> /// <returns>An array containing the attributes read from the screen buffer.</returns> public ConsoleCharAttribute[] ReadAtrributesXY(int nColors, int x, int y) { if (disposed) { throw new ObjectDisposedException(this.ToString()); } ConsoleCharAttribute[] buff = new ConsoleCharAttribute[nColors]; int colorsRead = 0; if (!WinCon.ReadConsoleOutputAttribute(handle, buff, nColors, new Coord((short)x, (short)y), ref colorsRead)) { throw new System.IO.IOException("Read error", Marshal.GetLastWin32Error()); } if (colorsRead < nColors) { ConsoleCharAttribute[] newBuff = new ConsoleCharAttribute[colorsRead]; Array.Copy(buff, newBuff, colorsRead); return newBuff; } return buff; }
public static extern bool SetConsoleTextAttribute( IntPtr hConsoleOutput, ConsoleCharAttribute attr);
/// <summary> /// Creates a new instance of the ConsoleCharInfo structure. /// </summary> /// <param name="aChar">The ASCII character.</param> /// <param name="attr">Character attributes.</param> public ConsoleCharInfo(byte aChar, ConsoleCharAttribute attr) { cUnicodeChar = '\x0'; bAsciiChar = aChar; this.attr = attr; }
/// <summary> /// Creates a new instance of the ConsoleCharInfo structure. /// </summary> /// <param name="uChar">The Unicode character.</param> /// <param name="attr">Character attributes.</param> public ConsoleCharInfo(char uChar, ConsoleCharAttribute attr) { bAsciiChar = 0; cUnicodeChar = uChar; this.attr = attr; }
public static extern bool FillConsoleOutputAttribute( IntPtr hConsoleOutput, ConsoleCharAttribute wAttribute, int nLength, Coord dwWriteCoord, ref int lpNumberOfAttrsWritten);
/// <summary> /// Fills character attributes at a given cursor position. /// </summary> /// <param name="fgColor">The foreground color to use in the fill.</param> /// <param name="bgColor">The background color to use in the fill.</param> /// <param name="numAttrs">The number of character cells to be filled with the attribute.</param> /// <param name="x">The column position where the fill operation is to start.</param> /// <param name="y">The row position where the fill operation is to start.</param> /// <returns>The number of character cells in which the attribute was written.</returns> public int FillAttributeXY(ConsoleColor fgColor, ConsoleColor bgColor, int numAttrs, int x, int y) { Coord pos = new Coord((short)x, (short)y); ConsoleCharAttribute attr = new ConsoleCharAttribute(fgColor, bgColor); int attrsWritten = 0; if (!WinCon.FillConsoleOutputAttribute(handle, attr, numAttrs, pos, ref attrsWritten)) { throw new ApplicationException("Error writing attributes"); } return attrsWritten; }