Example #1
0
        /// <summary>
        /// Displays in the form's title bar a question and collects an answer from the control DisplayedInfoTextBox.
        /// The form is displayed as a dialog box. Throws an exception if "question" is empty.
        /// </summary>
        public DialogResult AskQuestion(string question, ref string answer)
        {
            #region CheckOfArguments
#if DEBUG
            try
            {
                GeneralLibrary.GeneralClass.CheckNotEmpty(question);
            }
            catch
            {
                throw new ArgumentException("question should be a non-empty string");
            }
#endif
            #endregion

            this.Text = question;


            DialogResult ResultOfDialog = this.ShowDialog();

            bool RightAnswer = false;

            while
            (RightAnswer == false)
            {
                try
                {
                    answer = this.DisplayedInfoTextBox.Text;
                    GeneralClass.CheckNotEmpty(answer);
                    RightAnswer = true;
                }
                catch (Exception MyException)
                {
                    MessageBox.Show("The answer is supposed to be a non-empty string.");
                    RightAnswer = false;
                }
            }
            return(ResultOfDialog);
        }