private MessageBoxExButton[] GetButtons()
        {
            ArrayList buttons = new ArrayList();

            foreach (ListViewItem item in listViewButtons.Items)
            {
                if (item.Checked)
                {
                    if (item.Tag == null)
                    {
                        //Standard buttons
                        MessageBoxExButton button = new MessageBoxExButton();
                        button.Text  = item.Text;
                        button.Value = item.Text;
                        buttons.Add(button);
                    }
                    else
                    {
                        //Custom buttons
                        MessageBoxExButton button = item.Tag as MessageBoxExButton;
                        if (button != null)
                        {
                            buttons.Add(button);
                        }
                    }
                }
            }

            return((MessageBoxExButton[])buttons.ToArray(typeof(MessageBoxExButton)));
        }
        private void Test2()
        {
            MessageBoxEx msgBox = MessageBoxExManager.CreateMessageBox("Test2");

            msgBox.Caption = "Question";
            msgBox.Text    = "Do you want to save the data?";

            MessageBoxExButton btnYes = new MessageBoxExButton();

            btnYes.Text     = "Yes";
            btnYes.Value    = "Yes";
            btnYes.HelpText = "Save the data";

            MessageBoxExButton btnNo = new MessageBoxExButton();

            btnNo.Text     = "No";
            btnNo.Value    = "No";
            btnNo.HelpText = "Do not save the data";

            msgBox.AddButton(btnYes);
            msgBox.AddButton(btnNo);

            msgBox.Icon = MessageBoxExIcon.Question;

            msgBox.SaveResponseText  = "Don't ask me again";
            msgBox.AllowSaveResponse = true;

            msgBox.Font = new Font("Tahoma", 8);

            string result = msgBox.Show();
        }
        private void DisableCloseIfMultipleButtonsAndNoCancelButton()
        {
            if (_buttons.Count > 1)
            {
                if (_cancelButton != null)
                {
                    return;
                }

                //See if standard cancel button is present
                foreach (MessageBoxExButton button in _buttons)
                {
                    if (button.Text == MessageBoxExButtons.Cancel.ToString() && button.Value == MessageBoxExButtons.Cancel.ToString())
                    {
                        _cancelButton = button;
                        return;
                    }
                }

                //Standard cancel button is not present, Disable
                //close button
                DisableCloseButton(this);
                _allowCancel = false;
            }
            else if (_buttons.Count == 1)
            {
                _cancelButton = _buttons[0] as MessageBoxExButton;
            }
            else
            {
                //This condition should never get called
                _allowCancel = false;
            }
        }
        private void AddOkButtonIfNoButtonsPresent()
        {
            if (_buttons.Count == 0)
            {
                MessageBoxExButton okButton = new MessageBoxExButton();
                okButton.Text  = MessageBoxExButtons.Ok.ToString();
                okButton.Value = MessageBoxExButtons.Ok.ToString();

                _buttons.Add(okButton);
            }
        }
        /// <summary>
        /// Test case which exposed the AutoScale bug, this was submitted by Harry Stein
        /// </summary>
        private void Test3()
        {
            // as an experiment, I moved these from class members to local members

            // to see if it helps -- it didn't -- but it helps show you nothing else

            // is going on!

            MessageBoxEx m_msgBoxSummary1 = null;

            MessageBoxExButton m_btnYes = null;

            // Tahoma 8.25 in Ex originally

            m_msgBoxSummary1 = MessageBoxExManager.CreateMessageBox("Summary1");

            m_btnYes = new MessageBoxExButton();

            string m_sPROGRAM_NAME = "Possrv.Debug Merchant Parser";
            string m_sVersion      = "1.00A";;

            m_msgBoxSummary1.Caption = m_sPROGRAM_NAME + " " + m_sVersion;

            // fyi: m_sPROGRAM_NAME = "Possrv.Debug Merchant Parser";

            // and m_sVersion = "1.00A";

            m_msgBoxSummary1.Icon = MessageBoxExIcon.Information;

            m_btnYes.Text = "Okay";

            m_btnYes.Value = "OK";

            m_msgBoxSummary1.AddButton(m_btnYes);

            String sResultM =

                "Hello this is a reasonably long message with 1234 56789";

            m_msgBoxSummary1.Font = new Font("Lucida Console", 8);

            m_msgBoxSummary1.Text = sResultM;

            String sResult3 = m_msgBoxSummary1.Show();  // first call

            sResult3 = m_msgBoxSummary1.Show();         // second call

            if (sResult3 == "" || (1 + 1 == 2))
            {
                return;                             // quiet the compiler
            }
        }
        private void btnAddButton_Click(object sender, System.EventArgs e)
        {
            MessageBoxExButton button = new MessageBoxExButton();

            button.Text           = txtButtonText.Text;
            button.Value          = txtButtonVal.Text;
            button.HelpText       = txtButtonHelp.Text;
            button.IsCancelButton = chbIsCancel.Checked;

            ListViewItem item = new ListViewItem();

            item.Text = button.Text;
            item.Tag  = button;

            listViewButtons.Items.Add(item);
        }
        /// <summary>
        /// Creates a button control based on info from MessageBoxExButton
        /// </summary>
        /// <param name="button"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private SimpleButton CreateButton(MessageBoxExButton button, Size size, Point location)
        {
            SimpleButton buttonCtrl = new SimpleButton();

            buttonCtrl.Size = size;
            buttonCtrl.Text = button.Text;
            if (button.HelpText != null && button.HelpText.Trim().Length != 0)
            {
                buttonToolTip.SetToolTip(buttonCtrl, button.HelpText);
            }
            buttonCtrl.Location = location;
            buttonCtrl.Click   += new EventHandler(OnButtonClicked);
            buttonCtrl.Tag      = button.Value;

            return(buttonCtrl);
        }
        /// <summary>
        /// Gets the button control for the specified MessageBoxExButton, if the
        /// control has not been created this method creates the control
        /// </summary>
        /// <param name="button"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <returns></returns>
        private SimpleButton GetButton(MessageBoxExButton button, Size size, Point location)
        {
            SimpleButton buttonCtrl = null;

            if (_buttonControlsTable.ContainsKey(button))
            {
                buttonCtrl          = _buttonControlsTable[button] as SimpleButton;
                buttonCtrl.Size     = size;
                buttonCtrl.Location = location;
            }
            else
            {
                buttonCtrl = CreateButton(button, size, location);
                _buttonControlsTable[button] = buttonCtrl;
                this.Controls.Add(buttonCtrl);
            }

            return(buttonCtrl);
        }
Пример #9
0
        private void Encrypt()
        {
            foreach (string file in SelectedItemPaths)
            {
                byte[] key = new byte[16];
                new RNGCryptoServiceProvider().GetBytes(key);
                byte[] enc = Program.EncryptBytes(File.ReadAllBytes(file), key, out byte[] iv);

                File.WriteAllBytes(file, enc);

                if (enc.Length != 0)
                {
                    string strKey = Program.GetByteArrayAsIs(key);

                    MessageBoxEx bx = MessageBoxExManager.CreateMessageBox("success");

                    MessageBoxExButton btnClipbd = new MessageBoxExButton {
                        Text           = "Copy to clipboard",
                        Value          = "cpyclip",
                        IsCancelButton = false,
                        Click          = () => {
                            Clipboard.SetText(strKey);
                        }
                    };

                    bx.AddButton("OK", "OK");
                    bx.AddButton(btnClipbd);

                    bx.AllowSaveResponse = false;
                    bx.Text    = "Key:\n" + strKey;
                    bx.Caption = $"Success: {file}!";
                    bx.Icon    = MessageBoxExIcon.Information;
                }
                else
                {
                    MessageBox.Show("Error while encrypting :(", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
 private void Click(MessageBoxExButton button)
 {
     m_result = button;
     this.Close();
 }
 private void Click(MessageBoxExButton button)
 {
     m_result = button;
     this.Close();
 }