Search code examples
c#messagebox

Another Messagebox


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 { ...... }


Solution

  • 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)
             { ...... }