public static DialogExResult Show(SystemIconType iconType, string title, string text, params string[] buttonNames) { var dialog = new DialogEx(iconType, title, text, buttonNames); dialog.ShowDialog(); return(dialog.DialogResult); }
public static DialogExResult Show(IWin32Window owner, SystemIconType iconType, string title, string text, params string[] buttonNames) { var dialog = new DialogEx(iconType, title, text, buttonNames); dialog.StartPosition = FormStartPosition.CenterParent; dialog.ShowDialog(owner); return(dialog.DialogResult); }
public DialogExResult AskQuestion(Guid questionID, SystemIconType iconType, string title, string text, params string[] buttonNames) { if (_autoAnswers.ContainsKey(questionID)) { return(_autoAnswers[questionID]); } var dialog = new QuestionDialog(iconType, title, text, buttonNames); dialog.ShowDialog(); if (dialog.AlwaysFlag) { _autoAnswers[questionID] = dialog.DialogResult; } return(dialog.DialogResult); }
protected DialogEx(SystemIconType iconType, string title, string text, params string[] buttonNames) { if (title == null) { throw new ArgumentNullException("title"); } if (text == null) { throw new ArgumentNullException("text"); } if (buttonNames.Length == 0) { buttonNames = new[] { "OK" } } ; if (buttonNames.Length > 5) { throw new ArgumentOutOfRangeException("buttonNames", "Cannot have more than 5 buttons"); } // clip the text if its too large if (text.Length > MaxTextLength) { text = text.Substring(0, MaxTextLength); } InitializeComponent(); this.Text = title; // determine size of form based on label/text if (!_textLabel.CanTextFit(text)) { var oldSize = _textLabel.Size; var newSize = _textLabel.FitSize(text, oldSize.Width); // we resize the form, not the label since the label is anchored to the form var heightDiff = newSize.Height - oldSize.Height; this.Height += (int)Math.Round(heightDiff); } _textLabel.Text = text; for (var i = 0; i < buttonNames.Length; i++) { switch (i) { case 0: button1.Visible = true; button1.Text = buttonNames[i]; break; case 1: button2.Visible = true; button2.Text = buttonNames[i]; break; case 2: button3.Visible = true; button3.Text = buttonNames[i]; break; case 3: button4.Visible = true; button4.Text = buttonNames[i]; break; } } for (var i = buttonNames.Length; i < 4; i++) { switch (i) { case 0: button1.Visible = false; break; case 1: button2.Visible = false; break; case 2: button3.Visible = false; break; case 3: button4.Visible = false; break; } } }
public QuestionDialog(SystemIconType iconType, string title, string text, params string[] buttonNames) : base(iconType, title, text, buttonNames) { InitializeComponent(); }