• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Famio
V2EX  ›  程序员

C#中如何设置 form 中的所有 button 控件为不启用?

  •  
  •   Famio · Oct 9, 2016 · 2741 views
    This topic created in 3527 days ago, the information mentioned may be changed or developed.
    我在 form 中有很多 button 控件,大概思路知道用 foreach 来做,但是试了一下好像没效果,有没有大神给个 demo 看看

    我的代码:
    foreach (Control ctr in this.Controls)
    {
    if (ctr is Button)
    {
    ctr.enabled = false;
    }
    }
    Supplement 1  ·  Oct 9, 2016
    我的控件层级关系: form→TabControl→TabPage→GroupBox→Button
    Supplement 2  ·  Oct 9, 2016
    搞定了,是我逻辑错了
    6 replies    2016-10-10 12:50:29 +08:00
    qwertyiuop
        1
    qwertyiuop  
       Oct 9, 2016
    binding enable

    如果不要取消态的话 直接设置 hitTestVisible ?

    或者直接把所有 button 放在一个 grid 里面 直接控制 grid 的 hitTestVisible

    好久没弄 c#了 说错了 见谅
    robinlovemaggie
        2
    robinlovemaggie  
       Oct 9, 2016
    button 继承一下,在 baseButton 里设置开关,不知道可不可行
    dong3580
        3
    dong3580  
       Oct 9, 2016
    @robinlovemaggie
    没必要,就跟他上面的写的那样, init 的时候加载一下方法就行了,不过窗体会卡一下,异步应该好点。
    Hyeongo
        4
    Hyeongo  
       Oct 9, 2016 via iPhone
    多写 html
    ifishman
        5
    ifishman  
       Oct 9, 2016 via Android
    还没看到第 3 条附言就知道是哪里的问题了, button 的父级元素是 groupbox 诶
    yejinmo
        6
    yejinmo  
       Oct 10, 2016
    能在 V 站看到 C#的帖子。。真不容易啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2956 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 09:13 · PVG 17:13 · LAX 02:13 · JFK 05:13
    ♥ Do have faith in what you're doing.