2
votes

I want to customize my message box. I have created my own MessageBox. because basic message box, i can not customize the font (bold, color,..etc)

The problem is how can I get the value if a user clicks the yes botton ?

 public partial class XtraForm_Message : DevExpress.XtraEditors.XtraForm
    {
        public XtraForm_Message()
        {
            InitializeComponent();
        }

        public XtraForm_Message(string ClostList, string Chauffeur)
            : this()
        {
            labelControl_Trans.Text = ClostList;
            labelControl_Chauffeur.Text = Chauffeur;
        }

        private void simpleButton_oui_Click(object sender, EventArgs e)
        {
               ??????
        }

        private void simpleButton_non_Click(object sender, EventArgs e)
        {
            this.Close();
        }

and I call it like this:

  XtraForm_Message LeMessage = new XtraForm_Message(ClosListLib, ChauffeurLib);
                        LeMessage.Show();

If user click yes then I will do { ...... }

4

4 Answers

3
votes

You have to use DialogResult:

 public partial class XtraForm_Message : DevExpress.XtraEditors.XtraForm
{
    public XtraForm_Message()
    {
        InitializeComponent();
    }

    public XtraForm_Message(string ClostList, string Chauffeur)
        : this()
    {
        labelControl_Trans.Text = ClostList;
        labelControl_Chauffeur.Text = Chauffeur;
    }

    private void simpleButton_oui_Click(object sender, EventArgs e)
    {
        DialogResult = DialogResult.Yes;
        this.Close();
    }

    private void simpleButton_non_Click(object sender, EventArgs e)
    {
        DialogResult = DialogResult.No;
        this.Close();
    }

and call it like this:

   XtraForm_Message LeMessage = new XtraForm_Message(ClosListLib, ChauffeurLib);
   if(LeMessage.ShowDialog() == DialogResult.Yes)
         { ...... }
2
votes
    private void simpleButton_oui_Click(object sender, EventArgs e)
    {
         this.DialogResult = DialogResult.Yes
    }
1
votes

Use DialogResult

For example

Public class CustMessagebox
{
        public DialogResult ShowMessage(string Message,...)
        {
            this.ShowDialog()
            ....
             if(YesButton.Clicked)
            {
              return DialogResult.Yes
            }
            elseif()
            {
             ....
            }
        }
}

call it like

if ( new CustMessageBox().ShowMessage("Alert") == DialogResult.Yes)
{ 
do something..
}
0
votes

Well the usual way for a MessageBox is this.

DialogResult result = MessageBox.Show("...", "...", MessageBoxButtons.YesNoCancel);

if (result == DialogResult.Yes)
{
...
}