[英]C# enabling or disabling control
So, I'm losing my mind over a bug in my software.所以,我对我的软件中的一个错误失去了理智。
I have this code, I use it 2 times in my software, the other function similar (with a different name) works normally.我有这个代码,我在我的软件中使用了 2 次,其他类似的功能(名称不同)正常工作。 But this one is inverted...
但是这个反了...
I mean by that : Instead of enabling the controls when the groupbox.text contains "INC", it disable them.我的意思是:当 groupbox.text 包含“INC”时,它不会启用控件,而是禁用它们。
Any idea on what is going on?知道发生了什么吗?
`private void Enable_disableSTM()
{
if (STM_groupBox.Text.Contains("INC"))
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
} `
Edit :编辑 :
Like I said, in my software I have this other function that is working fine.就像我说的那样,在我的软件中,我有另一个运行良好的功能。 I tried also to change my IF to
STM_Textbox_reademail.Text != ""
and it's still not working correctly.我也尝试将我的 IF 更改为
STM_Textbox_reademail.Text != ""
但它仍然无法正常工作。 It's inverted.倒过来了Enabling when it should not and Disabling too.
在不应该启用和禁用时启用。
`if (SQ_TextBox_reademail.Text != "")
{
SQ_radioButton_appel.Enabled = true;
SQ_radioButton_autre.Enabled = true;
SQ_radioButton_resolution.Enabled = true;
SQ_Textbox_SR.Enabled = true;
SQ_textBox_remarque.Enabled = true;
SQ_Dropdown_Sendto.Enabled = true;
SQ_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
SQ_radioButton_appel.Enabled = false;
SQ_radioButton_autre.Enabled = false;
SQ_radioButton_resolution.Enabled = false;
SQ_Textbox_SR.Enabled = false;
SQ_textBox_remarque.Enabled = false;
SQ_Dropdown_Sendto.Enabled = false;
SQ_pictureBox_Boutonenvoyer.Enabled = false;
} `
Edit 2 : Okay... I figured out something that works.编辑 2 :好的......我想出了一些有用的东西。 I'm calling my function at a different place now and it's working.
我现在在不同的地方调用我的函数并且它正在工作。 Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works!
仍然没有意义为什么我可以在同一个地方调用另一个并且它可以工作但是这个没有......但是嘿......现在它可以工作了! thanks all!
谢谢大家!
Your problem is that you are checking if a string contains the "INC" word in a case sensitive way the solution is changing the if statement to check in the string the inc word ignoring the case :您的问题是您正在以区分大小写的方式检查字符串是否包含“INC”单词,解决方案正在更改 if 语句以检查字符串中的 inc 单词忽略大小写:
private void Enable_disableSTM()
{
if (STM_groupBox.Text.IndexOf("INC", StringComparison.OrdinalIgnoreCase) >= 0;)
{
STM_radioButton_appel.Enabled = true;
STM_radioButton_autre.Enabled = true;
STM_radioButton_resolution.Enabled = true;
STM_Textbox_SR.Enabled = true;
STM_textBox_remarque.Enabled = true;
STM_Dropdown_Sendto.Enabled = true;
STM_pictureBox_Boutonenvoyer.Enabled = true;
}
else
{
STM_radioButton_appel.Enabled = false;
STM_radioButton_autre.Enabled = false;
STM_radioButton_resolution.Enabled = false;
STM_Textbox_SR.Enabled = false;
STM_textBox_remarque.Enabled = false;
STM_Dropdown_Sendto.Enabled = false;
STM_pictureBox_Boutonenvoyer.Enabled = false;
}
}
Okay... I figured out something that works.好的...我想出了一些有效的方法。 I'm calling my function at a different place now and it's working.
我现在在不同的地方调用我的函数并且它正在工作。 Still does not make sense why I can call the other one at the same place and it works but this one doesn't... but hey... now it works!
仍然没有意义为什么我可以在同一个地方调用另一个并且它可以工作但是这个没有......但是嘿......现在它可以工作了! thanks all!
谢谢大家!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.