Exemple #1
0
        public MessageDialog(
            string strCaption
            , string strMessage
            , string strDetail
            , MessageBoxIcon icon
            , DialogButton acceptButton
            , DialogButton cancelButton
            , DialogButton DlgButtonDefault
            , params DialogButton[] buttons)
        {
            InitializeComponent();
            DEFAULT_MESSAGE_HEIGHT = panelButtons.Bottom;

            // show text;
            this.Text            = strCaption;
            this.lblMessage.Text = strMessage;

            if (string.IsNullOrEmpty(strDetail))
            {
                strDetail = "";
            }

            this.txtDetail.Lines = strDetail.Split('\n');
            // show icon picture
            Icon   icoDisplay       = null;
            string strSoundFileName = string.Empty;

            switch (icon)
            {
            case MessageBoxIcon.Information:            // MessageBoxIcon.Information = MessageBoxIcon.Asterisk
                icoDisplay       = SystemIcons.Information;
                strSoundFileName = "SystemAsterisk";
                break;

            case MessageBoxIcon.Error:          // MessageBoxIcon.Error = MessageBoxIcon.Hand = MessageBoxIcon.Stop
                icoDisplay       = SystemIcons.Error;
                strSoundFileName = "SystemHand";
                break;

            case MessageBoxIcon.Warning:        // MessageBoxIcon.Warning = MessageBoxIcon.Exclamation
                icoDisplay       = SystemIcons.Warning;
                strSoundFileName = "SystemExclamation";
                break;

            case MessageBoxIcon.Question:
                icoDisplay       = SystemIcons.Question;
                strSoundFileName = "SystemAsterisk";
                break;

            case MessageBoxIcon.None:
                icoDisplay = SystemIcons.Application;
                break;
            }
            if (icoDisplay != null)
            {
                picIcon.Image = icoDisplay.ToBitmap();
                this.Icon     = icoDisplay;
            }
            else
            {
                picIcon.Image = SystemIcons.Application.ToBitmap();
                this.Icon     = SystemIcons.Application;
            }
            m_iLastPanelDetailHeight = panelDetail.Height;
            // make new button to be showed on screen
            if (buttons.Length <= 0)
            {   // not have button specify, so use OK button as default.
                buttons = new DialogButton[] { DialogButton.OK };
            }
            CreateButton(buttons, strDetail.Trim().Length > 0, acceptButton, cancelButton);
            ShowDetail(false, false, false);
            //	Set Default SimpleButton
            foreach (Button btn in panelButtons.Controls)
            {
                if (btn.Name == DlgButtonDefault.ToString())
                {
                    btn.Select();
                }
            }
            if (strSoundFileName != string.Empty)
            {
                try
                {
                    PlaySound(strSoundFileName, 0, (int)(SND.SND_ASYNC | SND.SND_ALIAS | SND.SND_NOWAIT));
                }
                catch { }
            }
        }