简体   繁体   English

在C#中,如何在第一次单击后禁用一个按钮,然后在单击另一个按钮后再次启用它?

[英]in c#, how can you disable a button after the 1st click, and enable it again after you click another button?

I cannot figure this out i'm making a windows form application with visual basic in c# i have a scan button and it scans everything in the folder and lists all of the files in the listbox 我不能弄清楚我正在用c#在Visual Basic中制作Windows窗体应用程序,我有一个扫描按钮,它会扫描文件夹中的所有内容并列出列表框中的所有文件

if you click it another time the list of files appear again how can you make it so you can only press the scan button once, and then you can press it again if you click the browse button? 如果您再次单击它,文件列表将再次出现,如何制作它,因此您只能按一次扫描按钮,然后如果您单击浏览按钮,则可以再次按它?

the browse button is to select the folder you want to scan 浏览按钮是选择要扫描的文件夹

thanks 谢谢

This is pretty trivial 这很琐碎

 private void ScanButtonClick(object sender, EventArgs e)
 {
      // do something
      (sender as Button).Enabled = false;
 }

 private void BrowseButtonClick(object sender, EventArgs e)
 {
      ScanButton.Enabled = true;
 }

Its a bit unclear if you're writing in C# or vb.net, but since the question is tagged as C#... 不清楚是使用C#还是vb.net编写,但由于该问题被标记为C#...

private void btnScan_Click(object sender, EventArgs e) {
    btnScan.Enabled = false;

    // other code here
}

private void btnBrowse_Click(object sender, EventArgs e) {
    btnScan.Enabled = true;

    //other code here
}

I tried this in my windows form application in C# and it works fine! 我在C#的Windows窗体应用程序中尝试了此操作,效果很好!

private void button3_Click_1(object sender, EventArgs e)
        {
           int count = 0;
           count++; 
           //add your code here

           if (count == 1) {
                button3.Enabled = false;
                //only one click allowed
           }           
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM