Пример #1
0
        /// <summary>
        /// Opens a UI
        /// </summary>
        /// <param name="presenter">UI presenter</param>
        /// <param name="modalDialog">Set to <c>true</c> to display the UI as a modal dialog</param>
        public DialogResult?OpenForm(FormPresenter presenter, bool modalDialog)
        {
            try
            {
                var form = presenter.FormView as Form;
                if (form == null)
                {
                    return(null);
                }

                form.Owner      = (Form)FormView;
                form.Activated += delegate { FormView.Visible = false; };

                if (modalDialog)
                {
                    var dialogResult = form.ShowDialog();
                    FormView.Visible = true;
                    return(dialogResult);
                }

                form.Closed += delegate { FormView.Visible = true; };
                form.Show();
            }
            catch (Exception)
            {
                FormView.Visible = true;
                throw;
            }
            return(null);
        }
Пример #2
0
        private static Form GetForm(FormPresenter presenter)
        {
            var form = presenter.FormView as Form;

            if (form == null)
            {
                throw new ArgumentException("form");
            }
            return(form);
        }
Пример #3
0
        /// <summary>
        /// Opens a Form
        /// </summary>
        /// <param name="owner">The owner of the dialog</param>
        /// <param name="presenter">The presenter of the form to display</param>
        /// <param name="modalDialog">
        /// Set to <c>true</c> to display the about box as a modal dialog, otherwise <c>false</c>,
        /// </param>
        /// <returns>Returns the <see cref="DialogResult"/> returned by the displayed form</returns>
        public static DialogResult OpenDialog(IFormView owner, FormPresenter presenter, bool modalDialog)
        {
            if (presenter == null)
            {
                throw new ArgumentNullException("presenter");
            }

            if (!(presenter.FormView is Form))
            {
                throw new ArgumentException("the FormView of the presenter parameter is not of type Form");
            }

            var form = GetForm(presenter);

            SetFormOwner(owner, form);

            if (modalDialog)
            {
                return(form.ShowDialog());
            }

            form.Show();
            return(DialogResult.None);
        }