我对 C# 非常陌生,并且正在使用 Winforms 进行我的研究项目。下面的代码没有做它的工作。当我的richComResults (richTextBox) 为空时,我希望出现一个消息框并说“没有什么要清除的!”,但它没有说出来,它显示的是/否对话框。
请你能指出我的错误吗?您的意见将不胜感激。谢谢你。
private void btnComClearAll_Click(object sender, EventArgs e)
{
if (richComResults == null)
{
MessageBox.Show("There is nothing to be cleared!");
}
if (richComResults != null)
{
DialogResult dialogResult = MessageBox.Show("Are you sure you want to clear the results?", "Warning", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
richComResults.Clear();
}
else if (dialogResult == DialogResult.No)
{
}
}
}