How to create a tab with buttons? (Addin, C#)

Ivan I. shared this question 2 years ago
Discussion Open

I created a class, but it doesn't display the tab.

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;


///
// using Mindjet.MindManager.Interop;
using MM = Mindjet.MindManager.Interop;
using System.Windows.Forms;

namespace AddinTempl_3403.Core.RibbonTab2
{
class RibbonTab2
{
// Application === === === === === === === === === === === === === === === === === === === === === === === === === ===
MM.Application m_MindManager;

private static string DemoName = "Demo";

// AppRibbonTab === === === === === === === === === === === === === === === === === === === === === === === === === ===
MM.ribbonTab AppRibbonTab;
private readonly string TabCaption = DemoName + "Tab" + "/n" + "X"; // Alt + X - ??? ????? ??? ???????
private readonly string TabURI = "http://www.mindmanager.com/api/documentation/demos/ribbontab";

// AppRibbonGroup === === === === === === === === === === === === === === === === === === === === === === === === === ===
MM.RibbonGroup AppRibbonGroup;
private readonly string GroupCaption = DemoName + "Group" + "/n" + "X"; // '??? ?????? ??? ?????
private readonly string groupURI = "http://www.mindmanager.com/api/documentation/demos/ribbongroup";

// Control1 === === === === === === === === === === === === === === === === === === === === === === === === === ===
MM.Control Control1;

// command1 === === === === === === === === === === === === === === === === === === === === === === === === === ===
MM.Command command1;
private readonly static string CommandCaption = DemoName + "Cmd" + "/n" + "C"; // 'C - ??? ????? ???????
private readonly string CommandToolTip = "Create a new document" + "/n" + CommandCaption;


private readonly string ImagePath = $"{Environment.CurrentDirectory}" + @"\media\img\0000.jpg";
private readonly string AddInName = "Create a new document";

// private readonly string PATH = $"{Environment.CurrentDirectory}\\todoDataList.json";
// z:\vs\csharp\prb\3403\01_pr\01\Project\AddinTempl_3403\AddinTempl_3403\media\img\0000.jpg


public RibbonTab2(object application, string AddInName)
{
m_MindManager = application as MM.Application;

AppRibbonTab = m_MindManager.Ribbon.Tabs.Add(0, TabCaption, TabURI); // ???????? ??????? ?? ????? (' add a tab to the ribbon)
AppRibbonGroup = AppRibbonTab.Groups.Add(0, GroupCaption, groupURI, ImagePath); // ???????? ?????? ?? ??????? (' add a group to the tab)

command1 = m_MindManager.Commands.Add(AddInName, "DemoName");
command1.Caption = CommandCaption;
command1.ToolTip = CommandToolTip;


command1.SetDynamicMenu(Mindjet.MindManager.Interop.MmDynamicMenu.mmDynamicMenuTools, true);
//btn_1.UpdateState += new Mindjet.MindManager.Interop.ICommandEvents_UpdateStateEventHandler(mmCommand_UpdateState);
//btn_1.Click += new Mindjet.MindManager.Interop.ICommandEvents_ClickEventHandler(mmCommand_Click);


// command1.UpdateState += new Mindjet.MindManager.Interop.ICommandEvents_UpdateStateEventHandler(btn_1_UpdateState);
//command1.Click += new Mindjet.MindManager.Interop.ICommandEvents_ClickEventHandler(btn_1_Click);
command1.UpdateState += Command1_UpdateState;
command1.Click += Command1_Click;

Control1 = AppRibbonGroup.GroupControls.AddButton(command1);
// Control1.Caption = "Control1";
}

private void Command1_UpdateState(ref bool pEnabled, ref bool pChecked)
{
// throw new NotImplementedException();
}

private void Command1_Click()
{
MessageBox.Show(" Command1_Click ");
// throw new NotImplementedException();
}
}
}

Replies (1)

photo
1

Hello Ivan

I have not studied the code in detail, but here is where I would start:

  • Does your add-in connect properly and run the OnConnection method?
  • Where is the method RibbonTab2() called? Is it called from the OnConnection handler? As far as I can see, tab should be added if this method is called.
  • I note you are adding menu button instead of a ribbon button, so there are no buttons in the group. Menu buttons exist outside the tabs, in context menus elsewhere in the interface. The dynamic menu MmDynamicMenuTools is an old menu that is not present today. However, this would not be the reason that the tab does not appear.

---