43.2.7. Register Ribbon Icon using ProcessNet General

../_images/image01220.png

Figure 43.14 User Icon on Ribbon

The user can customize the ribbon layout and register ProcessNet function. However, this feature is available only in ProcessNet Register (General).

Following things are supported:

  • Creation ribbon tab

  • Creation ribbon group

  • Creation ribbon icon

  • Register the ProcessNet function to the icon

Creation custom group and icon

The user can create ribbon group and icon.

  • Casting the ribbon Manager interface: IRibbonManager ribbonManager = application.RibbonManager;

  • Find the ribbon tab “Customize”: IRibbonTab ribbonTab = ribbonManager.FindRibbonTab(“Customize”);

  • Create the ribbon Group: IRibbonGroup ribbonGroup = ribbonTab.AddRibbonGroup(“PNet Example”);

  • Create the ribbon icon : IMenuControl menuControl = ribbonGroup.AddMenuControl(MenuControlType.MenuControlType_Button, 8001);

Register ProcessNet function to ribbon icon

The user can register ProcessNet function to ribbon icon.

  • Set using ProcessNet function: IMenuControl.UseProcessNetFunction = true

  • Set the ProcessNet dll path: IMenuControl.ProcessNetDllPath = ProcessNetDllPath;

  • Set the function name in the ProcessNet dll: IMenuControl.ProcessNetFunctionName = “CreateBodyExample”;

  • Set the ProcessNet type : IMenuControl.ProcessNetType = ProcessNetType.ProcessNetType_General;

Sample Code

The user can use example code from ProcessNet example project
Project location : <Install Dir>\Help\Examples\ProcessNet
public void RegisterFunction ()
{
   IRibbonManager ribbonManager = application.RibbonManager;
   IRibbonTab ribbonTab = ribbonManager.FindRibbonTab("Customize");
   IRibbonGroup ribbonGroup = ribbonTab.AddRibbonGroup("PNet Example");

   //ID for user created processNet function must be between 8000 - 8999.
   IMenuControl menuControl = ribbonGroup.AddMenuControl(MenuControlType.MenuControlType_Button, 8001);

   // Set example control information.
   IntPtr iIcon = ProcessNet.Properties.Resources.example.GetHicon();
   menuControl.SetIcon(iIcon);
   menuControl.UseBigIcon = true;
   menuControl.Caption = "MyExample";
   menuControl.Tooltip = "MyTooltip";

   //menuControl.Description = "MyDescription";
   menuControl.UseProcessNetFunction = true; //if ID is not between 8000 - 8999, this can set ID to 8000

   // Get current ProcessNet dll fullpath. 'ProcessNetDllPath' must be absolute path.
   string assemblyname = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
   string codeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;

   UriBuilder uri = new UriBuilder(codeBase);
   string ProcessNetDllPath = Uri.UnescapeDataString(uri.Path);

   menuControl.ProcessNetDllPath = ProcessNetDllPath;
   menuControl.ProcessNetFunctionName = "CreateBodyExample";
   menuControl.ProcessNetType = ProcessNetType.ProcessNetType_General;
}