MapInfo Pro Developers User Group

Expand all | Collapse all

Copy to clipboard via MapBasic

Jump to Best Answer
  • 1.  Copy to clipboard via MapBasic

    Posted 16 days ago
    I've been reviewing my Table Information MBX tool (available for download from the community site).

    Currently, the tool displays the various table/query properties in EditText controls.  This looks visually clearer and has the benefit of allowing the user to select the text and copy it to the clipboard.  I often copy a table path or SQL query syntax to the clipboard to use again.

    The downside of having the attributes displayed as EditText controls is that they appear editable, when in fact they are not editable (however, I would like to be able to update the tool to allow the friendly name field to be editable through this interface).

    If I changed the attributes to StaticText controls, is there a way through MapBasic to add a button to copy the control value string to the clipboard?  Eg. a button at the end of the field for the table path or SQL Syntax which says "copy to clipboard".

    Send


    ------------------------------
    Kalu Ribush
    Senior Mapping Specialist
    Department of Economic Development, Jobs, Transport and Resources (DEDJTR)
    Melbourne
    ------------------------------


  • 2.  RE: Copy to clipboard via MapBasic

    Posted 15 days ago
    Whilst from what I can see there is not simple mapbasic command to copy a string variable to the clipboard, I did work out I can use the code below:

          dim strCopyText as string

          strCopyText = "the quick brown fox ..."

          'create temp table
          Create Table "_temp" (Text Char(254)) file GetFolderPath$(5)+"_temp.TAB" TYPE NATIVE Charset "WindowsLatin1" ' save to MyDocs folder

         ' insert text
         Insert into "_temp" (Text) Values (strCopyText)

         ' Select table
         Select * from _temp

         ' browse table so it can be copied
         browse * from selection

         ' copy to clipboard
         Run Menu command 203

         Drop table _temp



    ------------------------------
    Kalu Ribush
    Senior Mapping Specialist
    Department of Economic Development, Jobs, Transport and Resources (DEDJTR)
    Melbourne
    ------------------------------



  • 3.  RE: Copy to clipboard via MapBasic
    Best Answer

    Pitney Bowes
    Posted 15 days ago
    Hi Kalu,

    You can use the C# Clipboard.SetText method to put string into clipboard from mapbasic.
    Just define below method in you MB code and call it.

    Declare Method SetText Class "System.Windows.Clipboard" Lib "presentationcore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Alias SetText(ByVal p1 as String)


    Thanks
    Anshul

    ------------------------------
    Anshul Goel
    Knowledge Community Shared Account
    Shelton CT
    ------------------------------



  • 4.  RE: Copy to clipboard via MapBasic

    Posted 11 days ago
    Thanks Anshul

    That worked perfectly.  Better than my work around.

    Regards, Kalu

    ------------------------------
    Kalu Ribush
    Senior Mapping Specialist
    Department of Economic Development, Jobs, Transport and Resources (DEDJTR)
    Melbourne
    ------------------------------



  • 5.  RE: Copy to clipboard via MapBasic

    Community Manager
    Posted 11 days ago
    Hi Kalu! It looks like you may have gotten an answer here on the Knowledge Communities; if so, I'm glad! If you have a spare moment, would you be willing to give a "Best Answer" mark to the suggestion that helped you out? You can do this by clicking the down arrow next to Reply on the response, and choose "make Best Answer" from the list. This will help others in the future identify the suggestion as something that worked for you if they have a similar question.

    You can read more about Best Answers in this FAQ post.

    Thank you!

    ------------------------------
    Sydney Lawton
    Community Manager
    ------------------------------



  • 6.  RE: Copy to clipboard via MapBasic

    Posted 11 days ago
    As for read-only EditText controls, you can make then Disabled which will prevent the user from editing the text

    ------------------------------
    Peter Horsbøll Møller
    Pitney Bowes
    ------------------------------



  • 7.  RE: Copy to clipboard via MapBasic

    Posted 10 days ago
    Hi Peter,
    I did look at using Disable, but it also greys-out the control (both the box and the text).
    I've updated the Table Information Tool and opted for using ListBox controls with a single entry, as they have more visual contrast (white background) and are not edible.
    With one exception for the Table Path (as this may require multiple lines if the string is long) - I used a combination of EditText (disabled) and StaticText.  I used EditText for the background box (grey) and static text over the top.  If I only used a EditText control (disabled), then both the box and the text would be grey.  By using a combo, the box is greyed out, but the text is still black.
    Note - I've submitted this updated version to be loaded on the community site/market place.


    ------------------------------
    Kalu Ribush
    Senior Mapping Specialist
    Department of Economic Development, Jobs, Transport and Resources (DEDJTR)
    Melbourne
    ------------------------------