private string JustifyString(string str, LineJustification justification) { string justified = str; int whitespace = WIDTH - str.Length; if (whitespace > 0) { switch (justification) { case LineJustification.Left: // do nothing, already left justified break; case LineJustification.Center: if (whitespace % 2 == 0) { justified = WhiteSpace(whitespace / 2) + str + WhiteSpace(whitespace / 2); } else { justified = WhiteSpace(whitespace / 2) + str + WhiteSpace((whitespace - 1) / 2); } break; case LineJustification.Right: justified = WhiteSpace(whitespace) + str; break; } } return(justified); }
private string JustifyString(string str, LineJustification justification) { string justified = str; int whitespace = WIDTH - str.Length; if (whitespace > 0) { switch (justification) { case LineJustification.Left: // do nothing, already left justified break; case LineJustification.Center: if (whitespace % 2 == 0) { justified = WhiteSpace(whitespace / 2) + str + WhiteSpace(whitespace / 2); } else { justified = WhiteSpace(whitespace / 2) + str + WhiteSpace((whitespace - 1) / 2); } break; case LineJustification.Right: justified = WhiteSpace(whitespace) + str; break; } } return justified; }
public void WriteStringOnLine(string str, DisplayLine line = DisplayLine.LineOne, LineJustification justification = LineJustification.Left) { SendCommand((int)line); if (justification != LineJustification.Left) { str = JustifyString(str, justification); } byte[] asciiValues = Encoding.ASCII.GetBytes(str); for (int i = 0; i < str.Length && i < WIDTH; i++) { SendData(asciiValues[i]); } }