void Init() { Dialog.KeepWindowTitle = true; SetSize(Progress.FORM_WIDTH, (CanCancel ? 7 : 5) + _LineCount); _textActivity = new IText[_LineCount]; for (int iLine = 0; iLine < _LineCount; ++iLine) { _textActivity[iLine] = Dialog.AddText(5, -1, 5 + Progress.TEXT_WIDTH - 1, string.Empty); } _textProgress = Dialog.AddText(5, -1, 5 + Progress.TEXT_WIDTH - 1, string.Empty); if (CanCancel) { Dialog.AddText(5, -1, 0, string.Empty).Separator = 1; IButton button = Dialog.AddButton(0, -1, _jobThread == null ? "Cancel" : "Abort"); button.CenterGroup = true; Dialog.Default = button; } Dialog.Initialized += OnInitialized; Dialog.Closing += OnClosing; Dialog.Idled += OnIdled; }
/// <summary> /// displays a simple dialog with a button to close it /// </summary> /// <returns>The dialog.</returns> /// <param name="title">Title.</param> /// <param name="messageText">Message text.</param> /// <param name="closeButtonText">Close button text.</param> public Dialog ShowDialog(string title, string messageText, string closeButtonText) { var skin = Skin.CreateDefaultSkin(); var style = new WindowStyle { Background = new PrimitiveDrawable(new Color(50, 50, 50)), StageBackground = new PrimitiveDrawable(new Color(0, 0, 0, 150)) }; var dialog = new Dialog(title, style); dialog.GetTitleLabel().GetStyle().Background = new PrimitiveDrawable(new Color(55, 100, 100)); dialog.Pad(20, 5, 5, 5); dialog.AddText(messageText); dialog.AddButton(new TextButton(closeButtonText, skin)).OnClicked += butt => dialog.Hide(); dialog.Show(Stage); return(dialog); }
void Init() { List <string> lines = Utility.StringToList(_Message); var text = Utility.WrapText(lines, Console.WindowWidth - 14, Console.WindowHeight - 8); var textWidth = Utility.GetTextWidth(text); var textHeight = text.Count(); IButton[] buttons = new IButton[_Buttons.Length]; _Buttons[_DefaultButton] += " (00)"; int buttonsWidth = 0; for (int key = 0; key < _Buttons.Length; key++) { buttonsWidth += _Buttons[key].Replace("&", "").Length + 5; } buttonsWidth--; SetSize(AUX_WIDTH + (textWidth > buttonsWidth ? textWidth : buttonsWidth), AUX_HEIGHT + textHeight); foreach (var line in text) { Dialog.AddText(5, -1, 5 + textWidth - 1, line); } Dialog.AddText(5, -1, 0, string.Empty).Separator = 1; for (int key = 0; key < _Buttons.Length; key++) { buttons[key] = Dialog.AddButton(0, AUX_HEIGHT + textHeight - 3, _Buttons[key]); buttons[key].CenterGroup = true; buttons[key].Data = key; buttonsWidth += _Buttons[key].Replace("&", "").Length + 5; } var timer = new System.Timers.Timer(1000); bool AutoClose = false; Dialog.Default = buttons[_DefaultButton]; Dialog.Default.Text = _Buttons[_DefaultButton].Replace("(00)", string.Format("({0:00})", 10)); Dialog.SetFocus(buttons[_DefaultButton].Id); Dialog.Closing += (object sender, ClosingEventArgs e) => { timer.Enabled = false; _clickedButton = (int)Dialog.Focused.Data; }; Dialog.Idled += (object sender, EventArgs e) => { if (AutoClose) { Dialog.SetFocus(buttons[_DefaultButton].Id); Dialog.Close(); } }; Dialog.KeyPressed += (object sender, KeyPressedEventArgs e) => { timer.Enabled = false; }; var i = 9; timer.Elapsed += (object sender, System.Timers.ElapsedEventArgs e) => { if (i < 0) { AutoClose = true; timer.Enabled = false; return; } // potentially dangerous, but seems working fine Dialog.Default.Text = _Buttons[_DefaultButton].Replace("(00)", string.Format("({0:00})", i--)); }; timer.Enabled = true; }