我在第一个窗体上有计时器控件(和一个按钮)。
想法是,当用户点击按钮时,会显示带有新按钮的新模态窗口,询问他是否想在点击模态窗体的按钮时停止计时器。
你能帮我实现吗?
请您参考如下方法:
您也可以根据答案在带有问题的表单上设置DialogResult,并在主对话框中查看结果。
ConfirmationForm confirmationForm = new ConfirmationForm();
DialogResult dialogResult = confirmationForm.ShowDialog();
if (dialogResult == DialogResult.OK)
{
// Stop timer here
}
或者使用标准对话框
DialogResult dialogResult = MessageBox.Show("Are you sure you want to stop the timer?", "Stop timer", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
// Stop timer here
}
编辑:将 confirmationForm.Show 更改为 confirmationForm.ShowDialog。
