简体   繁体   English

如何在C#上启用checkbox.checked的文本框?

[英]How to enable textbox on checkbox.checked on C#?

I'm new to C#. 我是C#的新手。 The textbox1 is locked by default and I want to enable it the moment I check the checkbox1. 默认情况下,textbox1是锁定的,我想在选中checkbox1时启用它。 I use the following code, but it doesn't work: 我使用以下代码,但不起作用:

private void checkboxevent(object sender, EventArgs e)
{
    if (checkBox1.Checked = true)
        textBox1.Enabled = true;
    else
        textBox1.Enabled = false;
}

= is the assignment operator == is the equality operator =是赋值运算符==是相等运算符

Take a close look at the following statement 仔细看下面的语句

if (checkBox1.Checked = true)

add autopostaback="true" for your checkbox in order to refresh the page whenever the checkbox is checked or unchecked 为您的checkbox添加autopostaback="true" ,以便在选中或取消选中复选框时刷新页面

I'm assuming that you're talking about webforms. 我假设您是在谈论网络表单。

Also = true is incorrect. = true是不正确的。 It should be == true 应该是== true

Also, == true is altogether redundant. 同样, == true完全是多余的。 if (checkbox.Checked) is all you need. if (checkbox.Checked)就足够了。

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

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