如何在C#windows窗体中单击一次后禁用该按钮 [英] How to make a button to be disabled after it has been clicked once in C# windows form

查看:589
本文介绍了如何在C#windows窗体中单击一次后禁用该按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天请创建一个cbt应用程序,并有一个开始和一个提交按钮。每当点击开始按钮时,它将把用户带到考试区域,然后当点击提交按钮时,用户到达那里但我想要单击提交按钮后永久禁用的开始按钮我不希望同一个用户进行两次检查。学生仪表板是开始按钮的位置。



我尝试过:



 public void submit_Click(object sender,EventArgs e)
{
StudentDashBoard db = new StudentDashBoard();
db.btnstart.Enabled = false;

解决方案

似乎在按钮点击时,您创建了一个新的实例表单。

您没有(也不应该)。

因为当执行事件处理程序时,表单已经实例化,您只需要访问其中的btntart实例:

  public   void  submit_Click( object  sender,EventArgs e)
{
btnstart.Enabled = false ;
// ...
}



希望这会有所帮助。麻烦。


Good day Please i created a cbt application and have a start and a submit button.Whenever the start button is clicked it will take the user to the exam area then when the submit button is clicked the user get there result but i want the start button to be disabled permanently after the submit button has been clicked i dont want the same user to do the exam twice.Where Student dashboard is where the start button is.

What I have tried:

  public void submit_Click(object sender, EventArgs e)
        {
 StudentDashBoard db = new StudentDashBoard();
db.btnstart.Enabled = false;

解决方案

It seems that, on button click, you create a new instance of the form.
You don't have to (and should not).
Since when the event hanler is executed, the form is already instantiated, you just need to access the btntart instance in it:

public void submit_Click(object sender, EventArgs e)
{
   btnstart.Enabled = false;
   // ...
}


Hope this helps. Kindly.


这篇关于如何在C#windows窗体中单击一次后禁用该按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆