且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#windows窗体中单击一次后禁用该按钮

更新时间:2022-12-23 13:59:38

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

您没有(也不应该)。

因为当执行事件处理程序时,表单已经实例化,您只需要访问其中的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.