locked
Is it wrong for an application to copy to clipboard? RRS feed

  • Question

  • In an add-in to Visual Studio I want to take copy of the source code in the code window to the Clipboard using the following:   

    objTextDoc = CType(_applicationObject.ActiveDocument.Object("TextDocument"), TextDocument) Selection = objTextDoc.Selection() Selection.SelectAll() Selection.Copy()

    The reason is that Visual Studio copies the source code in RTF format to the clipboard that includes syntax highlighted source code , I need the syntax highlighted code.

    I have read so many articles on the internet that say that no application should overwrite the clipboard contents. I tend to agree with that.  

    If I could find another way to get hold of syntax highlighted code for a projectItem in a VS Project I would prefer not to use the clipboard.

    What advice do you guys have?

    Joginder Nahil
    www.starprinttools.com



    • Edited by J S Nahil Saturday, May 11, 2013 8:07 AM
    • Moved by Amanda Zhu Monday, May 13, 2013 7:00 AM
    Saturday, May 11, 2013 7:36 AM

Answers

  • Hi Joginder,

    You can use the clipboard as long as you preserve its previous contents.


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    • Proposed as answer by Ego Jiang Tuesday, May 14, 2013 8:28 AM
    • Marked as answer by Ego Jiang Wednesday, May 29, 2013 9:35 AM
    Monday, May 13, 2013 7:47 AM
  • Hi Carlos,

    Thanks for that advice. I will do that. Would you point me to source code that I can trust that it will work in all circumstances and clipboard formats? That would be a great help.

    Regards,

    Joginder Nahil

    • Marked as answer by J S Nahil Thursday, June 6, 2013 8:29 AM
    Monday, May 13, 2013 9:00 AM

All replies

  • Hello,

    I have moved this thread to Visual Studio Extensibility forum for better response.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 13, 2013 7:00 AM
  • Hi Joginder,

    You can use the clipboard as long as you preserve its previous contents.


    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/

    • Proposed as answer by Ego Jiang Tuesday, May 14, 2013 8:28 AM
    • Marked as answer by Ego Jiang Wednesday, May 29, 2013 9:35 AM
    Monday, May 13, 2013 7:47 AM
  • Hi Carlos,

    Thanks for that advice. I will do that. Would you point me to source code that I can trust that it will work in all circumstances and clipboard formats? That would be a great help.

    Regards,

    Joginder Nahil

    • Marked as answer by J S Nahil Thursday, June 6, 2013 8:29 AM
    Monday, May 13, 2013 9:00 AM