public static bool confirm(string message) { string rez; if (message.Length > 5 * Console.WindowWidth / 6) { rez = Func.strWithLength(message, 5 * Console.WindowWidth / 6); } else if (message.Length < 25) { rez = Func.strWithLength(message, 25); } else { rez = message; } int height = 7; int width = rez.Length + 4; int x = (Console.WindowWidth - (width)) / 2; int y = (Console.WindowHeight - height) / 2; Border.DrawBorder(x, y, width, height); UI.drawRect(x + 1, y + 1, width - 2, height - 2, ConsoleColor.DarkGray); Console.SetCursorPosition(x + 2, y + 2); Console.Write(rez); ConsoleElement yes = new ConsoleElement(x + 2, y + 4, (width - 4) / 2, 1, "YES"); ConsoleElement no = new ConsoleElement(x + 2 + (width - 4) / 2, y + 4, (width - 4) / 2, 1, "NO"); ConsoleKeyInfo key; yes.active(); no.deActive(); bool isYes = true; while (true) { key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { break; } else if (key.Key == ConsoleKey.LeftArrow) { isYes = true; yes.active(); no.deActive(); } else if (key.Key == ConsoleKey.RightArrow) { isYes = false; no.active(); yes.deActive(); } } if (parent != null) { parent.redraw(); } return(isYes); }
public static int selectiveWindow(ArrayList messages) { ArrayList selections = new ArrayList(); ConsoleElement tElem; int h = messages.Count + 4; int w = 85; int x = (Console.WindowWidth - w) / 2; int y = (Console.WindowHeight - h) / 2; Border.DrawBorder(x, y, w, h); UI.drawRect(x + 1, y + 1, w - 2, h - 2, ConsoleColor.DarkGray); x += 2; y += 2; w -= 4; for (int i = 0; i < messages.Count; i++) { tElem = new ConsoleElement(x, y + i, w, h, (string)messages[i], ConsoleElementStyle.LEFT); selections.Add(tElem); if (i == 0) { tElem.active(); } else { tElem.deActive(); } } int active = 0; ConsoleKeyInfo key; while (true) { key = Console.ReadKey(); if (key.Key == ConsoleKey.DownArrow) { ((ConsoleElement)selections[active]).deActive(); active++; active %= messages.Count; ((ConsoleElement)selections[active]).active(); } else if (key.Key == ConsoleKey.UpArrow) { ((ConsoleElement)selections[active]).deActive(); active--; if (active < 0) { active = messages.Count - 1; } ((ConsoleElement)selections[active]).active(); } else if (key.Key == ConsoleKey.Enter) { parent.redraw(); return(active); } else if (key.Key == ConsoleKey.Escape) { parent.redraw(); return(-1); } Console.SetCursorPosition(0, Console.WindowHeight - 1); } }
public static int selectiveWindow(ArrayList messages) { ArrayList selections = new ArrayList(); ConsoleElement tElem; int h = messages.Count + 4; int w = 85; int x = (Console.WindowWidth - w) / 2; int y = (Console.WindowHeight - h) / 2; Border.DrawBorder(x, y, w, h); UI.drawRect(x + 1, y + 1, w - 2, h - 2, ConsoleColor.DarkGray); x += 2; y += 2; w -= 4; for (int i = 0; i < messages.Count; i++) { tElem = new ConsoleElement(x, y + i, w, h, (string)messages[i], ConsoleElementStyle.LEFT); selections.Add(tElem); if (i == 0) tElem.active(); else tElem.deActive(); } int active = 0; ConsoleKeyInfo key; while (true) { key = Console.ReadKey(); if (key.Key == ConsoleKey.DownArrow) { ((ConsoleElement)selections[active]).deActive(); active++; active %= messages.Count; ((ConsoleElement)selections[active]).active(); } else if (key.Key == ConsoleKey.UpArrow) { ((ConsoleElement)selections[active]).deActive(); active--; if (active < 0) active = messages.Count - 1; ((ConsoleElement)selections[active]).active(); } else if (key.Key == ConsoleKey.Enter) { parent.redraw(); return active; } else if (key.Key == ConsoleKey.Escape) { parent.redraw(); return -1; } Console.SetCursorPosition(0, Console.WindowHeight - 1); } }
public static bool confirm(string message) { string rez; if (message.Length > 5 * Console.WindowWidth / 6) rez = Func.strWithLength(message, 5 * Console.WindowWidth / 6); else if (message.Length < 25) rez = Func.strWithLength(message, 25); else rez = message; int height = 7; int width = rez.Length + 4; int x = (Console.WindowWidth - (width)) / 2; int y = (Console.WindowHeight - height) / 2; Border.DrawBorder(x, y, width, height); UI.drawRect(x + 1, y + 1, width - 2, height - 2, ConsoleColor.DarkGray); Console.SetCursorPosition(x + 2, y + 2); Console.Write(rez); ConsoleElement yes = new ConsoleElement(x + 2, y + 4, (width - 4) / 2, 1, "YES"); ConsoleElement no = new ConsoleElement(x + 2 + (width - 4) / 2, y + 4, (width - 4) / 2, 1, "NO"); ConsoleKeyInfo key; yes.active(); no.deActive(); bool isYes = true; while (true) { key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { break; } else if (key.Key == ConsoleKey.LeftArrow) { isYes = true; yes.active(); no.deActive(); } else if (key.Key == ConsoleKey.RightArrow) { isYes = false; no.active(); yes.deActive(); } } if (parent != null) parent.redraw(); return isYes; }