コード例 #1
0
        private static IWin32Window ValidateOptions(IWin32Window owner, MessageBoxOptions options, HelpInfo helpInfo)
        {
            // Check if trying to show a message box from a non-interactive process, this is not possible
            if (!SystemInformation.UserInteractive &&
                ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0))
            {
                throw new InvalidOperationException("Cannot show modal dialog when non-interactive");
            }

            // Check if trying to show a message box from a service and the owner has been specified, this is not possible
            if ((owner != null) &&
                ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0))
            {
                throw new ArgumentException(@"Cannot show message box from a service with an owner specified", nameof(options));
            }

            // Check if trying to show a message box from a service and help information is specified, this is not possible
            if ((helpInfo != null) &&
                ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) != 0))
            {
                throw new ArgumentException(@"Cannot show message box from a service with help specified", nameof(options));
            }

            IWin32Window showOwner = null;

            if ((helpInfo != null) ||
                ((options & (MessageBoxOptions.ServiceNotification | MessageBoxOptions.DefaultDesktopOnly)) == 0))
            {
                // If do not have an owner passed in then get the active window and use that instead
                showOwner = owner ?? Control.FromHandle(PI.GetActiveWindow());
            }

            return(showOwner);
        }
コード例 #2
0
        /// <summary>Internals the show.</summary>
        /// <param name="owner">The owner.</param>
        /// <param name="title">The title.</param>
        /// <param name="message">The message.</param>
        /// <param name="prompt">The prompt.</param>
        /// <param name="okText">The ok text.</param>
        /// <param name="cancelText">The cancel text.</param>
        /// <param name="passwordEnabled">if set to <c>true</c> [password enabled].</param>
        /// <param name="startPosition">The start position.</param>
        /// <param name="inputTextAlignment">The input text alignment.</param>
        /// <returns></returns>
        private static string InternalShow(IWin32Window owner, string title, string message, string prompt = "", string okText = "O&k", string cancelText = "&Cancel", bool passwordEnabled = false, FormStartPosition startPosition = FormStartPosition.WindowsDefaultLocation, HorizontalAlignment inputTextAlignment = HorizontalAlignment.Left)
        {
            IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow());

            using (KryptonInputBox kib = new KryptonInputBox(title, message, prompt, okText, cancelText, passwordEnabled, startPosition, inputTextAlignment))
            {
                kib.StartPosition = showOwner == null ? startPosition : startPosition;

                return(kib.ShowDialog(showOwner) == DialogResult.OK ? kib.GetUserResponse() : string.Empty);
            }
        }
コード例 #3
0
        private static string InternalShow(IWin32Window owner,
                                           string prompt,
                                           string caption,
                                           string defaultResponse,
                                           char passwordChar)
        {
            // If do not have an owner passed in then get the active window and use that instead
            IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow());

            // Show input box window as a modal dialog and then dispose of it afterwards
            using (KryptonInputBoxOld ib = new KryptonInputBoxOld(prompt, caption, defaultResponse, passwordChar))
            {
                ib.StartPosition = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent;

                return(ib.ShowDialog(showOwner) == DialogResult.OK ? ib.InputResponse : string.Empty);
            }
        }
コード例 #4
0
        private static string InternalShow(IWin32Window owner,
                                           string prompt,
                                           string caption,
                                           string defaultResponse,
                                           string cueText,
                                           Color cueColour,
                                           Font cueTypeface,
                                           bool usePasswordOption)
        {
            // If do not have an owner passed in then get the active window and use that instead
            IWin32Window showOwner = owner ?? FromHandle(PI.GetActiveWindow());

            // Show input box window as a modal dialog and then dispose of it afterwards
            using KryptonInputBox ib = new(prompt, caption, defaultResponse, cueText, cueColour, cueTypeface, usePasswordOption);
            ib.StartPosition         = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent;

            return(ib.ShowDialog(showOwner) == DialogResult.OK ? ib.InputResponse : string.Empty);
        }
        /// <summary>
        /// Internals the show.
        /// </summary>
        /// <param name="owner">The owner.</param>
        /// <param name="messageContent">Content of the message.</param>
        /// <param name="caption">The caption.</param>
        /// <param name="iconVisibility">The icon visibility.</param>
        /// <param name="borderType">Type of the border.</param>
        /// <param name="buttonCount">The button count.</param>
        /// <param name="buttons">The buttons.</param>
        /// <param name="options">The options.</param>
        /// <param name="helpInfo">The help information.</param>
        /// <param name="defaultButton">The default button.</param>
        /// <param name="icon">The icon.</param>
        /// <param name="result">The result.</param>
        /// <param name="buttonTextCollection">The button text collection.</param>
        /// <param name="customIcon">The custom icon.</param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException">Cannot show modal dialog when non-interactive</exception>
        /// <exception cref="ArgumentException">
        /// Cannot show message box from a service with an owner specified - options
        /// or
        /// Cannot show message box from a service with help specified - options
        /// </exception>
        private static KryptonMessageBoxExtendedResult InternalShow(IWin32Window owner, string messageContent, string caption, KryptonMessageBoxExtendedApplicationIconVisibility iconVisibility, KryptonMessageBoxExtendedBorderType borderType, KryptonMessageBoxExtendedBoxButtonCount buttonCount, KryptonMessageBoxExtendedButtons buttons, KryptonMessageBoxExtendedBoxOptions options, HelpInformation helpInfo = null, KryptonMessageBoxExtendedDefaultButton defaultButton = KryptonMessageBoxExtendedDefaultButton.BUTTON1, KryptonMessageBoxExtendedIcon icon = KryptonMessageBoxExtendedIcon.NONE, string[] buttonTextCollection = null, string checkBoxText = null, Image customIcon = null) // KryptonMessageBoxExtendedResult result = KryptonMessageBoxExtendedResult.OK,
        {
            // Check if trying to show a message box from a non-interactive process, this is not possible
            if (!SystemInformation.UserInteractive && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) == 0))
            {
                throw new InvalidOperationException("Cannot show modal dialog when non-interactive");
            }

            // Check if trying to show a message box from a service and the owner has been specified, this is not possible
            if ((owner != null) && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) != 0))
            {
                throw new ArgumentException(@"Cannot show message box from a service with an owner specified", nameof(options));
            }

            // Check if trying to show a message box from a service and help information is specified, this is not possible
            if ((helpInfo != null) && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) != 0))
            {
                throw new ArgumentException(@"Cannot show message box from a service with help specified", nameof(options));
            }

            // If help information provided or we are not a service/default desktop application then grab an owner for showing the message box
            IWin32Window showOwner = null;

            if ((helpInfo != null) || ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) == 0))
            {
                // If do not have an owner passed in then get the active window and use that instead
                showOwner = owner ?? FromHandle(PI.GetActiveWindow());
            }

            using (ExtendedKryptonMessageboxOld ekmb = new ExtendedKryptonMessageboxOld(showOwner, messageContent, caption, iconVisibility, borderType, buttonCount, buttons, options, helpInfo, defaultButton, icon, buttonTextCollection, checkBoxText, customIcon))
            {
                ekmb.StartPosition = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent;

                return(ekmb.ShowDialogExtended(showOwner));
            }
        }