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 create a ToolButton

    Employee
    Posted 10-26-2017 09:43

    You showed how to create a standard button, a standard PushButton in the earlier 32 bit versions.

    How can I create a ToolButton?



  • 2.  RE: How do I create a ToolButton

    Employee
    Posted 10-26-2017 06:33
    Edited by Peter Møller 12-19-2019 04:40

    Yes, I took the easy way and just showed the very basic PushButton, or Button Control.

    You can of course also create a ToolButton which oinly needs a few more settings, such as DrawMode and Icon.

    Button Control

    This is the basics of the Button Control ignoring the ToolTips and Icons as that's the same for both types but they need to use different procedures, see under ToolButton Control:

    'Now add a button to the group's controls collection with a name, caption and enumerated ControlType
    mtsBtn = MICtrlCollAddStrStrInt(mtsGroupControlColl, "btnConnectDots", "Connect The Dots", ControlType_Button)
    'Set command to the button
    Call SetRbnBtnCtrlCallingHandler(mtsBtn, "ConnectTheDots")

    ToolButton Control

    The ToolButton control gets added using the same function but the ControlType must be different:

    mtsBtnTool = MICtrlCollAddStrStrInt(mtsGroupControlColl, "btnConnectDots", "Connect The Dots", ControlType_ToolButton)

    It also needs a handler but that needs to reach to a "tool" click and be able to fetch the coordinates from the clicks
    Call SetRbnToolBtnCtrlCallingHandler(mtsBtnTool, "ConnectTheDotsUsingTool")

    And then we need to specify a DrawMode for the ToolButton:

    Call SetRbnToolBtnCtrlDrawMode(mtsBtnTool, DM_CUSTOM_POLYLINE)

    And we should specify a cursor. Notice that I convert it to string as it requires a string value which also can hold the File in case of a custom cursor:

    Call SetRbnToolBtnCtrlCursor(mtsBtnTool, Str$(MI_CURSOR_CROSS))

     And here is the specific procedure calls to use for ToolTips and Icons:

    tsToolTip = New_MapInfoRibbonToolTip()
    Call SetMIRbnToolTipToolTipDescription(tsToolTip, "Connect The Dots Tool")
    Call SetMIRbnToolTipToolTipText(tsToolTip, "Creates a polygon or polyline by drawing")
    Call SetMIRbnToolTipToolTipDisabledText(tsToolTip, "Make sure to select records from a layer")
    Call SetRbnToolBtnCtrlToolTip(mtsBtnTool, tsToolTip)
    Call SetRbnToolBtnCtrlSmallIcon(mtsBtnTool, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_16x16.png", 0))
    Call SetRbnToolBtnCtrlLargeIcon(mtsBtnTool, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_32x32.png", 0))
    Call SetRbnToolBtnCtrlIsLarge(mtsBtnTool, TRUE)