public Hub() { UpdateBase = new FmdcEventHandler(Hub_UpdateBase); listMainchat = new ListBox(0, 2, Console.WindowWidth - 21, Console.WindowHeight - 4, ref msgList); listUserlist = new ListBox(Console.WindowWidth - 20, 2, 20, Console.WindowHeight - 4, ref userList); input = new TextField(0, Console.WindowHeight - 1, Console.WindowWidth); updateTimer.Interval = 1 * 1000; updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(updateTimer_Elapsed); updateTimer.Start(); // Controls listMainchat.BgColor = ConsoleColor.Gray; listMainchat.FgColor = ConsoleColor.Black; Controls.Add(listMainchat); listUserlist.BgColor = ConsoleColor.Gray; listUserlist.FgColor = ConsoleColor.Blue; Controls.Add(listUserlist); input.BgColor = ConsoleColor.White; input.FgColor = ConsoleColor.Black; Controls.Add(input); }
public override void Show() { if (setting == null) { setting = new HubSetting(); int width = 20; int height = 5; int px = (Console.WindowWidth / 2) - width; int py = (Console.WindowHeight / 2) - height; Rectangle popup = new Rectangle(px, py, width * 2, height * 2, ConsoleColor.Gray, ConsoleColor.DarkBlue); popup.Show(); Label popupTitle = new Label(px, py, "Connection Setting", width * 2); popupTitle.BgColor = ConsoleColor.Blue; popupTitle.FgColor = ConsoleColor.DarkBlue; popupTitle.Show(); TextField address = new TextField(px + 1, py + 2, "IP/DNS:", 31); address.BgColor = ConsoleColor.DarkBlue; address.FgColor = ConsoleColor.Gray; address.Show(); TextField port = new TextField(px + 1, py + 4, "Port:", 33); port.BgColor = ConsoleColor.DarkBlue; port.FgColor = ConsoleColor.Gray; port.Show(); TextField nick = new TextField(px + 1, py + 6, "DisplayName:", 26); nick.BgColor = ConsoleColor.DarkBlue; nick.FgColor = ConsoleColor.Gray; nick.Show(); Button buttonConnect = new Button(px + 1, py + 8, "Connect"); buttonConnect.OnSelect += new EventHandler(buttonConnect_OnSelect); buttonConnect.BgColor = ConsoleColor.DarkBlue; buttonConnect.FgColor = ConsoleColor.Gray; buttonConnect.Show(); // Select one at a time System.Net.IPAddress ip = null; do { address.Focus(); if (!string.IsNullOrEmpty(address.Input)) { try { ip = System.Net.Dns.GetHostEntry(address.Input).AddressList[0]; } catch (System.Exception) { // We are not going to try to catch this as developer that used this class made something wrong if this has to be thrown. try { ip = System.Net.IPAddress.Parse(address.Input); } catch { } } } } while (ip == null); setting.Address = address.Input; int p = 0; // Port do { port.Focus(); try { p = int.Parse(port.Input); } catch { } } while (p <= 0 && p > 65535); setting.Port = p; do { nick.Focus(); } while (string.IsNullOrEmpty(nick.Input)); setting.DisplayName = nick.Input; buttonConnect.Focus(); setting.Protocol = "Auto"; setting.Port = -1; } base.Show(); }