public static void PrintFreeStringBundle(FreeStringBundle bundle) { int columnPoint; switch (bundle.GetAlignment()) { case Alignment.Left: columnPoint = bundle.GetPositionX(); break; case Alignment.Right: columnPoint = bundle.GetPositionX() + bundle.GetMaxTextLength() - 1; break; default: columnPoint = (bundle.GetMaxTextLength()) / 2 + bundle.GetPositionX() - 1; break; } int currentRow = bundle.GetPositionY(); foreach (string s in bundle.GetContents()) { FreeString current = new FreeString(s, columnPoint, currentRow, bundle.GetTextColor(), bundle.GetBackgroundColor(), bundle.GetAlignment()); PrintFreeString(current); currentRow++; } CleanUp(); }
public void FreeStringBundleDemo() { FreeStringBundle fsBundle = new FreeStringBundle(30, 5, 50, Color.Black, Color.Green, Alignment.Center); Border border = new Border(fsBundle.GetPositionX() - 1 , fsBundle.GetPositionY() - 1, fsBundle.GetMaxTextLength() + 2, 10); fsBundle.Add("FirstLine"); fsBundle.Add("This Line exceed the 20 character limit and will be warped to next line."); fsBundle.Add("Third Imput but in fourth line"); fsBundle.Add("This Line Has Exactly 50 characters.##############"); fsBundle.Add("This Line Has Exactly 49 characters.#############"); fsBundle.Add("This Line Has Exactly 51 characters.###############"); bool exit = false; while (!exit) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; Console.Clear(); Console.SetCursorPosition(10, 20); Console.Write("Q | LeftAlign, W | CenterAlign, E | RightAlign"); border.Print(); fsBundle.Print(); var input = Console.ReadKey(true); switch (input.Key) { case ConsoleKey.Escape: exit = true; break; case ConsoleKey.LeftArrow: fsBundle.Move(-1, 0); border.Move(-1, 0); break; case ConsoleKey.UpArrow: fsBundle.Move(0, -1); border.Move(0, -1); break; case ConsoleKey.RightArrow: fsBundle.Move(1, 0); border.Move(1, 0); break; case ConsoleKey.DownArrow: fsBundle.Move(0, 1); border.Move(0, 1); break; case ConsoleKey.Q: fsBundle.LeftAlign(); break; case ConsoleKey.W: fsBundle.CenterAlign(); break; case ConsoleKey.E: fsBundle.RightAlign(); break; } } }