禁用菜单项时出现问题 [英] Problem in disabling menu Item

查看:103
本文介绍了禁用菜单项时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经渲染了两个带有图标的菜单项.根据某些条件,我想以编程方式启用和禁用菜单项,并且工作正常.我的问题是,当菜单项处于禁用状态时,该图标似乎没有被禁用,它与启用菜单项时的状态保持不变.

但是正如我在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>
>
代码以禁用菜单:-

<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( ( IMenuCommandService ;

CommandID

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

CommandID

cmdID = ;

cmdID = null;

 

MenuCommand menuCmd = ;

MenuCommand menuCmd = null;

 


cmdID =


cmdID =

( GuidList int ) .activityLogCommand);

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

 

如果 (menuCmd!= )

if (menuCmd != null)

{
menuCmd.Enabled =

false ;
}


感谢,
Ankesh.

menuCmd = mcs.FindCommand(cmdID);

menuCmd = mcs.FindCommand(cmdID);

推荐答案

您好,Ankesh772,

您是要隐藏此菜单项吗?在这种情况下,可以将MenuItem的Visiable属性指定为false,有关更多信息,请通过以下链接引用MenuItem的属性:

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:

http://msdn.microsoft.com/en-us/library/system.componentmodel.design.menucommand_properties.aspx

If I misnuderstood you, or you have any questions, please let me know.

Best Regards,
Nancy


这篇关于禁用菜单项时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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