如何使用其名称OR标签禁用Control? [英] how can i disable Control with its name OR tag ?

查看:78
本文介绍了如何使用其名称OR标签禁用Control?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的winForm中有一个按钮,它有一个名称和标签!

我想找到并禁用它!

我该怎么办?

hi , i have a button in my winForm ,, and it has a name and tag !
i want to find it and disable it!
how can i do it ?

推荐答案





试试这个:

Hi,

Try this:
IEnumerable<Button> buttons = this.Controls.OfType<Button>();
foreach (Button b in buttons)
{
      if (b.Name == "name" || b.Tag == "tag")
      {
          b.Enabled = false;
      }
}



如果您的表单上还有容器,例如 Panel s,那么你应该使用递归来禁用面板上的一些按钮。



希望这会有所帮助。


If you''ve also containers on your form, such as Panels, then you should use recursion to disable also some buttons on the panel.

Hope this helps.


of当然它有一个名字..
of course it has a name..
Button someButton = new Button();
//...

someButton.Enabled = false;


这篇关于如何使用其名称OR标签禁用Control?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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