How to get the “real” value of the Visible property?

前端 未结 4 948
执笔经年
执笔经年 2021-01-11 11:40

If you set the Visible property of a Windows Forms control to true, that property still returns false if any of the control\'s parent windows are hidden. Is there a way to g

4条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 11:56

    I have same issue with classes derived from 'ToolStripItem' base class. so I used Available property value to check if item will be displayed or not. problem solved. Sample:

    ToolStripItem curItm = menuStrip1.Items[i] as ToolStripItem;
    if(curItm is ToolStripItem && curItm.Available) DoAnyThing();
    

    In this sample 'curItm' is an instance of of ToolStripItem derived class.

    This problem with Visible/Enabled properties in .Net controls that depend on parent container's Visible/Enabled must be solved by .Net team. I create a costume property named IsVisible/IsEnabled in my own classes that return assigned value for Visible/Enabled properties and not the value that depend on parent container.

提交回复
热议问题