我想自定义我的留言框。我创建了自己的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();
如果用户单击是,那么我将{......}
答案 0 :(得分: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)
{ ...... }
答案 1 :(得分:2)
private void simpleButton_oui_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Yes
}
答案 2 :(得分: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..
}
答案 3 :(得分:0)
对于MessageBox来说,通常的方法就是这样。
DialogResult result = MessageBox.Show("...", "...", MessageBoxButtons.YesNoCancel);
if (result == DialogResult.Yes)
{
...
}