添加命令到我的按钮

时间:2015-08-18 14:29:11

标签: c# button visual-studio-2013 command

我刚刚为IDE工具栏创建了一些按钮。

但是现在我如何填写一些功能,如打开一个新窗口或计算数字?

这是我的ISIPlusToolbar.vcst数据。

    <Button guid="guidISIPlusToolbarCmdSet" id="cmdidOptions" priority="0x0101" type="Button">
    <Parent guid="guidISIPlusToolbarCmdSet" id="ISIPlusToolbarGroup" />
    <Icon guid="guidImages" id="bmpPic1" />
    <CommandFlag>TextChanges</CommandFlag>
    <Strings>
      <CommandName>cmdidOptions</CommandName>
      <ButtonText>Options</ButtonText>
    </Strings>
  </Button>

  <Button guid="guidISIPlusToolbarCmdSet" id="cmdidNSLManager" priority="0x0101" type="Button">
    <Parent guid="guidISIPlusToolbarCmdSet" id="ISIPlusToolbarGroup" />
    <Icon guid="guidImages" id="bmpPic2" />
    <CommandFlag>TextChanges</CommandFlag>
    <Strings>
      <CommandName>cmdidNSLManager</CommandName>
      <ButtonText>NSL Manager</ButtonText>
    </Strings>
  </Button>

  <Button guid="guidISIPlusToolbarCmdSet" id="cmdidIconPicker" priority="0x0101" type="Button">
    <Parent guid="guidISIPlusToolbarCmdSet" id="ISIPlusToolbarGroup" />
    <Icon guid="guidImages" id="bmpPicX" />
    <CommandFlag>TextChanges</CommandFlag>
    <Strings>
      <CommandName>cmdidIconPicker</CommandName>
      <ButtonText>Icon Picker</ButtonText>
    </Strings>
  </Button>

这是我的Package.cs,我已经尝试过这些按钮中的至少一个,但它不起作用,我不知道为什么。

      protected override void Initialize()
    {
        Debug.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
        base.Initialize();

        // Add our command handlers for menu (commands must exist in the .vsct file)
        OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
        if ( null != mcs )
        {
            // Create the command for the menu item.
            CommandID menuCommandID = new CommandID(GuidList.guidISIPlusToolbarCmdSet, (int)PkgCmdIDList.cmdidISIPlusToolbar);
            OleMenuCommand menuItem = new OleMenuCommand(MenuItemCallback, menuCommandID );
            menuItem.BeforeQueryStatus +=
                new EventHandler(OnBeforeQueryStatus);
            mcs.AddCommand( menuItem );
        }
    }
    #endregion


    private void OnBeforeQueryStatus(object sender, EventArgs e)
    {
        int counter = 1;
        var myCommand = sender as OleMenuCommand;
        if (null != myCommand)
        {
            counter++;
            Console.WriteLine(counter);
        }
    }

感谢您的帮助

0 个答案:

没有答案