示例#1
0
 /// <summary>
 /// show form as dialog with given parameters
 /// </summary>
 /// <param name="AMessage">Message to be displayed to the user</param>
 /// <param name="ACaption">Caption of the dialog window</param>
 /// <param name="AChkOptionText">Text to be shown with check box (check box hidden if text empty)</param>
 /// <param name="AButtons">Button set to be displayed</param>
 /// <param name="ADefaultButton">The button with a default action</param>
 /// <param name="AIcon">Icon to be displayed</param>
 /// <returns></returns>
 public TFrmExtendedMessageBox.TResult ShowDialog(string AMessage, string ACaption, string AChkOptionText,
                                                  TFrmExtendedMessageBox.TButtons AButtons,
                                                  TFrmExtendedMessageBox.TDefaultButton ADefaultButton,
                                                  TFrmExtendedMessageBox.TIcon AIcon)
 {
     return(ShowDialog(AMessage, ACaption, AChkOptionText, AButtons, ADefaultButton, AIcon, false));
 }
示例#2
0
        /// <summary>
        /// show form as dialog with given parameters
        /// </summary>
        /// <param name="AMessage">Message to be displayed to the user</param>
        /// <param name="ACaption">Caption of the dialog window</param>
        /// <param name="AChkOptionText">Text to be shown with check box (check box hidden if text empty)</param>
        /// <param name="AButtons">Button set to be displayed</param>
        /// <param name="ADefaultButton">The button with a default action</param>
        /// <param name="AIcon">Icon to be displayed</param>
        /// <param name="AOptionSelected">initial value for option check box</param>
        /// <returns></returns>
        public TFrmExtendedMessageBox.TResult ShowDialog(string AMessage, string ACaption, string AChkOptionText,
                                                         TFrmExtendedMessageBox.TButtons AButtons,
                                                         TFrmExtendedMessageBox.TDefaultButton ADefaultButton,
                                                         TFrmExtendedMessageBox.TIcon AIcon,
                                                         bool AOptionSelected)
        {
            string  ResourceDirectory;
            string  IconFileName;
            ToolTip ButtonTooltip = new ToolTip();

            // initialize return values
            FResult         = TResult.embrUndefined;
            FOptionSelected = AOptionSelected;

            txtMessage.Text            = AMessage;
            txtMessage.BorderStyle     = BorderStyle.FixedSingle;
            txtMessage.HideSelection   = true;
            txtMessage.SelectionStart  = 0;
            txtMessage.SelectionLength = 0;
            txtMessage.Font            = new System.Drawing.Font(txtMessage.Font, FontStyle.Regular);

            pnlLeftButtons.MinimumSize = new Size(btnHelp.Width + btnCopy.Width + 10, pnlLeftButtons.Height);

            ButtonTooltip.SetToolTip(btnHelp, "Help");
            ButtonTooltip.SetToolTip(btnCopy, "Copy to Clipboard");

            this.Text      = ACaption;
            chkOption.Text = AChkOptionText;

            if (AChkOptionText.Length == 0)
            {
                chkOption.Visible = false;
            }

            chkOption.Checked = AOptionSelected;

            this.MinimumSize = new System.Drawing.Size(pnlLeftButtons.Width + pnlRightButtons.Width, 250);

            btnYes.Visible      = false;
            btnYesToAll.Visible = false;
            btnNo.Visible       = false;
            btnNoToAll.Visible  = false;
            btnOK.Visible       = false;
            btnCancel.Visible   = false;

            FDefaultButton = ADefaultButton;

            switch (AButtons)
            {
            case TButtons.embbYesYesToAllNoCancel:
                btnYes.Visible      = true;
                btnYesToAll.Visible = true;
                btnNo.Visible       = true;
                btnCancel.Visible   = true;
                break;

            case TButtons.embbYesYesToAllNoNoToAllCancel:
                btnYes.Visible      = true;
                btnYesToAll.Visible = true;
                btnNo.Visible       = true;
                btnNoToAll.Visible  = true;
                btnCancel.Visible   = true;
                break;

            case TButtons.embbYesYesToAllNoNoToAll:
                btnYes.Visible      = true;
                btnYesToAll.Visible = true;
                btnNo.Visible       = true;
                btnNoToAll.Visible  = true;
                break;

            case TButtons.embbYesNo:
                btnYes.Visible = true;
                btnNo.Visible  = true;
                break;

            case TButtons.embbYesNoCancel:
                btnYes.Visible    = true;
                btnNo.Visible     = true;
                btnCancel.Visible = true;
                break;

            case TButtons.embbOK:
                btnOK.Visible = true;
                break;

            case TButtons.embbOKCancel:
                btnOK.Visible     = true;
                btnCancel.Visible = true;
                break;

            default:
                break;
            }

            // dispose of items in case they were used already earlier
            if (FBitmap != null)
            {
                FBitmap.Dispose();
            }

            // find the right icon name
            switch (AIcon)
            {
            case TIcon.embiQuestion:
                IconFileName = "Help.ico";
                break;

            case TIcon.embiInformation:
                IconFileName = "PetraInformation.ico";
                break;

            case TIcon.embiWarning:
                IconFileName = "Warning.ico";
                break;

            case TIcon.embiError:
                IconFileName = "Error.ico";
                break;

            default:
                IconFileName = "";
                break;
            }

            if (FIconControl == null)
            {
                FIconControl = new PictureBox();

                // Stretches the image to fit the pictureBox.
                FIconControl.SizeMode   = PictureBoxSizeMode.StretchImage;
                FIconControl.ClientSize = new Size(30, 30);
                pnlIcon.Padding         = new Padding(3, 3, 3, 3);
            }

            // load and set the image
            ResourceDirectory = TAppSettingsManager.GetValue("Resource.Dir");

            if ((AIcon != TIcon.embiNone) &&
                System.IO.File.Exists(ResourceDirectory + System.IO.Path.DirectorySeparatorChar + IconFileName))
            {
                pnlIcon.Visible    = true;
                FBitmap            = new System.Drawing.Bitmap(ResourceDirectory + System.IO.Path.DirectorySeparatorChar + IconFileName);
                FIconControl.Image = (Image)FBitmap;

                if (!pnlIcon.Controls.Contains(FIconControl))
                {
                    pnlIcon.Controls.Add(FIconControl);
                }
            }
            else
            {
                // remove icon panel if it already exists
                if (pnlIcon.Controls.Contains(FIconControl))
                {
                    pnlIcon.Controls.Remove(FIconControl);
                }

                pnlIcon.Visible = false;
            }

            // remove the controlbox as we do not need these options (min, max and close_
            this.ControlBox = false;

            // now show the actual dialog
            this.StartPosition = FormStartPosition.CenterScreen;
            this.ShowDialog();

            // FResult is initialized when buttons are pressed
            return(FResult);
        }