禁用菜单项时出现问题

编程入门 行业动态 更新时间:2024-10-09 08:27:59
本文介绍了禁用菜单项时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经渲染了两个带有图标的菜单项.根据某些条件,我想以编程方式启用和禁用菜单项,并且工作正常.我的问题是,当菜单项处于禁用状态时,该图标似乎没有被禁用,它与启用菜单项时的状态保持不变. 但是正如我在IDE中看到的那样菜单项处于禁用状态时,图标的颜色也会改变.我是否需要根据菜单的状态动态更改图标,或者我缺少要做的事情? 可以吗?正文可以帮助我解决它. 下面是代码.

I have rendered two menu items with icons. Based on some condition I want to enable and disable the menu items programatically and it is working fine. My problem is that when the menu item is in disabled state the icon does not seems to be disabled,it remains same as it was in when menu item was enabled.But as I have seen in the IDE the icon color also change when the menu item is in disabled state.Do I need to change the Icon dynamically based on the state of menu or I am missing something to do?Can any body help me to solve it.Following are the code.

<按钮guid =" guidVSPackage1CmdSet" id ="stdToolbarDisConnectBtn";优先级="0x0100&"; type =按钮"> <父guid ="guidVSPackage1CmdSet"; id ="KovairStdToolBarGroup"; /> .<!-< Icon guid ="disconnectImage" id ="bmpPic1" />-> .< Icon guid ="guidImages" id ="bmpPicX"; /> < CommandFlag> DefaultDisabled</CommandFlag> < ButtonText>与Omnibus服务器断开连接</ButtonText> ; id ="KovairMenuGroup"优先级="0x0500&"> 父guid ="guidVSPackage1CmdSet"; id =" KovairMenu"/</Group> < Menu guid =" guidVSPackage1CmdSet" id ="KovairMenu"优先级="0x700" type ="Menu"> <父guid ="guidSHLMainMenu"; id ="IDG_VS_MM_TOOLSADDINS" /> <字符串> < ButtonText>& amp; Kovair OmniBus</ButtonText> > 代码以禁用菜单:-

OleMenuCommandService

<Button guid="guidVSPackage1CmdSet" id="stdToolbarDisConnectBtn" priority="0x0100" type="Button">        <Parent guid="guidVSPackage1CmdSet" id="KovairStdToolBarGroup" />        <!--<Icon guid="disconnectImage" id="bmpPic1" />-->        <Icon guid="guidImages" id="bmpPicX" />        <CommandFlag>DefaultDisabled</CommandFlag>        <CommandFlag>DynamicVisibility</CommandFlag>        <Strings>          <CommandName>stdToolbarDisConnectBtn</CommandName>          <ButtonText>Disconnect From Omnibus Server</ButtonText>        </Strings>      </Button> <Group guid="guidVSPackage1CmdSet" id="KovairMenuGroup" priority="0x0500">        <Parent guid="guidVSPackage1CmdSet" id="KovairMenu"/>      </Group><Menu guid="guidVSPackage1CmdSet" id="KovairMenu" priority="0x700" type="Menu">        <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_TOOLSADDINS" />         <Strings>          <ButtonText>&amp;Kovair OmniBus</ButtonText>        </Strings>    </Menu>code to disable the menu:-

OleMenuCommandService

mcs = GetService( typeof ( IMenuCommandService )) 另存为 OleMenuCommandService ;

CommandID

mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

CommandID

cmdID = 空 ;

cmdID = null;

 

MenuCommand menuCmd = 空 ;

MenuCommand menuCmd = null;

 

cmdID =

cmdID =

新 CommandID ( GuidList .guidVSPackage1CmdSet,( int ) PkgCmdIDList .activityLogCommand);

new CommandID(GuidList.guidVSPackage1CmdSet, (int)PkgCmdIDList.activityLogCommand);

 

如果 (menuCmd!= 空 )

{ menuCmd.Enabled =

if (menuCmd != null)

{menuCmd.Enabled =

false ; } 感谢, Ankesh.

menuCmd = mcs.FindCommand(cmdID);

menuCmd = mcs.FindCommand(cmdID);

推荐答案

您好,Ankesh772, 您是要隐藏此菜单项吗?在这种情况下,可以将MenuItem的Visiable属性指定为false,有关更多信息,请通过以下链接引用MenuItem的属性: msdn.microsoft/en-us/library/systemponentmodel.design.menucommand_properties.aspx 如果我误解了您,或者您有任何疑问,请让我知道. 最诚挚的问候,南希 Hi Ankesh772,Do you mean you want to hide this menuitem if you have disabled it? If this is in the case, you can specify Visiable property of MenuItem to false, for more information, please refer to the properties of MenuItem with following link:msdn.microsoft/en-us/library/systemponentmodel.design.menucommand_properties.aspxIf I misnuderstood you, or you have any questions, please let me know.Best Regards,Nancy

更多推荐

禁用菜单项时出现问题

本文发布于:2023-11-28 10:38:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642059.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜单项

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!