开发者

Working with dialog boxes in C#

I have a Winforms application that has a message box. When the user clicks the "Generate Report" button, there's a question that's d开发者_运维知识库isplayed in the message box with Yes and No as options.

No matter what the user clicks, whether Yes or No, I don't want the report to be generated.

But on the other hand, I want the user to click on the generate button again to generate the report.

How do I do this in C# and Winforms?


You can use boolean flag:

private bool _isClicked = false;

public void Button1_OnClick(object sender, EventArgs e)
{
   if(!_isClicked)
   {
        // do show the message box here 
        _isClicked = true;
        return;
   }

   //generate the report here   
   _isClicked = false;   
}


Just store a flag in your application - set it to true when you want the button to actually generate the report. Then when the user clicks the button, you can check the flag and show the MessageBox if the flag isn't set, then set the flag based on the response. If the flag is set, then generate the report.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜