MapInfo Pro Developers User Group

Welcome to the MapInfo Pro Developers community!  We are a group dedicated to the discussion and understanding of MapBasic and .Net MapInfoPro AddIn development. Bring your questions and ideas here. This group includes several members of the Pro development team from around the world.

Please feel free to start a discussion in the discussion tab or join in a conversation.

Product Information  Ideas Portal  MapInfo Community Downloads

Discussions

Members

Resources

Events

 View Only
  • 1.  How do I add a toolbutton to the Ribbon using the RIBBONLib?

    Employee
    Posted 06-22-2017 07:51

    I have a few time seen questions related to adding toolbuttons to the Ribbon using the RIBBONLib. Often people find it easy to add a normal (Push)Button but find it hard to add a ToolButton.



  • 2.  RE: How do I add a toolbutton to the Ribbon using the RIBBONLib?
    Best Answer

    Employee
    Posted 06-22-2017 04:02
    Edited by Peter Møller 12-19-2019 04:43

    Adding a ToolButton is done similar to adding a standard Button.

    You first add the ToolButton and then you specify the behaviour and the visuals of the button.

    Here is an example:

     

    'First we add the control, the toolbutton
    nCtrlIdx = RBNGroupAddControl("DTRegionAdd", "Add to Region", "", ControlType_ToolButton, TAB_SPATIAL, TAB_GROUP_SPATIAL_EDIT)
    If nCtrlIdx > 0 Then
       'Then we design the visuals and the behaviour
       'Create & Set the button tooltip
       Call RBNControlSetToolTipIdx(nCtrlIdx, "DrawTools", "Add extra region to the selected region.", "Select a polygon from the editable layer.")
       'Set the button icon
       Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_LARGE, "", ApplicationDirectory$() & "Images\PolygonAdd_32.png")
       'The DrawMode and Cursor are specific to the ToolButton
       'Set DrawMode
       Call RBNControlSetDrawModeIdx(nCtrlIdx, DM_CUSTOM_POLYGON)
       'Set Cursor
       Call RBNControlSetMICursorIdx(nCtrlIdx, MI_CURSOR_CROSSHAIR, "")
       'Set Custom MapBasic Handle to the button
       Call RBNControlSetCustomMBXHandlerIdx(nCtrlIdx, "DTRegionAdd")
    End If
     

    In the case above, we add the ToolButton to the Edit group on the SPATIAL tab. To use the defines I use here, you need to include the file RibbonElements.def that also is included in the mbLibrary on Github.

    We set the drawmode to Polygon and the cursor to a standard Crosshair cursor.