Windows窗体 - ToolStripItem的Visible属性始终设置为false [英] Windows Forms - ToolStripItem Visible property is always set to false

查看:916
本文介绍了Windows窗体 - ToolStripItem的Visible属性始终设置为false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个 MDI Windows窗体应用程序。我父窗体有的ToolStrip 菜单和一些 ToolStripDropDownButtons 。我想改变 ToolStripDropDownButton 或者一些 ToolStripItems 可见属性code>(子按钮),它具有相应于用户的许可。

I'm working on a MDI Windows Forms application. My parent form has ToolStrip menu and some ToolStripDropDownButtons. I want to change the Visible property of the ToolStripDropDownButton or to some of the ToolStripItems (sub buttons) that it has accordingly to the permission of the user.

下面是我写的这个管理方法的一部分:

Here is the part of the method that I've wrote to manage this:

private void SetToolStripDropDownVisibility(ToolStripDropDownButton mainBtn, params ToolStripItem[] item)
{
     mainBtn.Visible = false;
     foreach (ToolStripItem tempItem in item)
     {
         tempItem.Visible = true;
     }
}



我路过作为第一个参数 ToolStripDropDownButton 和所有其他子键为PARAMS名单。然而,当我进入调试模式中的一部分的foreach(ToolStripItem的tempItem项) tempItem Visible属性被标记为假。在设计师然而,这个属性被设置为true。你可以看到,我甚至尝试明确地将值更改为真 - tempItem.Visible = TRUE; ,但它好像这条线无所事事。 可见遗体假的值,我不能改变它。

I'm passing as first argument the ToolStripDropDownButton and all other "sub buttons" as params list. However when I get into debug mode in the part foreach (ToolStripItem tempItem in item) the tempItem Visible property is marked as false. In the designer however this property is set to true. You can see that I even try explicitly to change the value to true - tempItem.Visible = true; but it seems as if this line is doing nothing. The value of Visible remains false and I can't change it.

这是该方法只是开始时,我不能考虑其他的代码可以搞砸与的ToolStrip 项目。我试图改变 mainBtn.Visible 的真或假的思想价值,也许有任何联系,但似乎这不是问题。那么,为什么发生这种情况,为什么我不能更改可见价值,当然没有办法做任何的想法。

This is just the begining of the method and I can't think of other code that can mess up with the ToolStrip items. I tried to change the value of mainBtn.Visible to true or false thinking that maybe there's any connection but it seems this is not the issues. So any idea why this is happening, why I cant change the Visible value and of course any way to do it.

推荐答案

解决方案是容易的,但并不明显。当我们与 ToolStripItems 来工作,这是 ToolSTripDropDownButton 的一部分,解决知名度问题,我们使用了解决的方式普通的按钮,我们必须使用可用属性。它恰好为此目的而设计。希望有人通过阅读这该怎么花更少的时间来处理这个问题!

The solution is easy and yet not obvious. When we have to work with ToolStripItems which are part of ToolSTripDropDownButton and solve visibility problem the way we used to solve it with ordinary buttons we have to use Available property. It is designed exactly for this purpose. Hope someone gonna spend less time dealing with this problem by reading this!

这篇关于Windows窗体 - ToolStripItem的Visible属性始终设置为false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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