2

我想自定义我的消息框。我创建了自己的 MessageBox。因为基本的消息框,我不能自定义字体(粗体,颜色,..等)

问题是如果用户单击“是”按钮,我如何获得该值?

 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();
        }

我这样称呼它:

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

如果用户单击是,那么我将执行 { ...... }

4

4 回答 4

3

您必须使用 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();
    }

并这样称呼它:

   XtraForm_Message LeMessage = new XtraForm_Message(ClosListLib, ChauffeurLib);
   if(LeMessage.ShowDialog() == DialogResult.Yes)
         { ...... }
于 2013-07-23T08:58:05.303 回答
2
    private void simpleButton_oui_Click(object sender, EventArgs e)
    {
         this.DialogResult = DialogResult.Yes
    }
于 2013-07-23T09:02:42.033 回答
1

采用DialogResult

例如

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

称之为

if ( new CustMessageBox().ShowMessage("Alert") == DialogResult.Yes)
{ 
do something..
}
于 2013-07-23T08:57:56.233 回答
0

好吧,MessageBox 的常用方法是这样的。

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

if (result == DialogResult.Yes)
{
...
}
于 2013-07-23T08:55:48.303 回答