Getting full paste (Text+Code)


  1. Posts : 3
    Windows 7
       #1

    Getting full paste (Text+Code)


    In windows, you can paste regular text (like from notepad to Word), and styled text (like copying colored text from one Word to another, or even text with bullets from here (chrome) to a Word document).
    I believe that when you "copy", you copy the text, along with meta-chars that are the style.
    How can I see these meta-chars? Is there A C# code that can do this?
    Last edited by RanC; 23 Dec 2016 at 09:39. Reason: Adding a possibility
      My Computer


  2. Posts : 630
    Windows 10 Pro 64 bit
       #2

    Are you referring to the source code of a web page? Right click the web page and select "View Page Source "
      My Computer


  3. Posts : 3
    Windows 7
    Thread Starter
       #3

    Not only source code. Say I copied styled text from Word. How can I know the style?
      My Computer


  4. Posts : 630
    Windows 10 Pro 64 bit
       #4

    If you copy styled text from one Word doc to another. Highlight the styled text in question and click the Home tab. Look under styles and that style should be highlighted. I hope this is this is what you are referring too.
      My Computer


  5. Posts : 3
    Windows 7
    Thread Starter
       #5

    Lance1 said:
    If you copy styled text from one Word doc to another. Highlight the styled text in question and click the Home tab. Look under styles and that style should be highlighted. I hope this is this is what you are referring too.
    No. What I mean is not only in Word. If I copied a text with bullets to Word (or any other program that supports text with bullets) - text with bullets would appear. If we have a program that supports colorful text, colorful text would appear. How do I know the style? If I copied blue text from Word, how would I know *programmatically* that its blue? How do I know what meta-singes are attached (I know how to programmatically invoke adding plain text to the clipboard via C#/Java - how do I invoke copying blue text?)?
      My Computer


  6. Posts : 2,468
    Windows 7 Ultimate x64
       #6

    So this is entirely a programming question?
    If so, the first thing to understand is how the clipboard really works.

    The clipboard works by holding data and its associated format. Each program specifies what format it's sending data in, so the pasting software knows how to deal with it. The trick that makes the clipboard so flexible is that it allows programs to set multiple copies of the very same data, in different formats, at the same time.
    When you copy a chunk of text from Word, what actually happens is that Word places the text multiple times, one in plain text, other in rich text format, some other proprietary format and so on. What this allows is to provide a wide range of options for programs to paste from. Notepad may pick the plain text, Word would pick the most complete format, another editor maybe would pick RTF, and so on.

    Back to the original question, when you read data from the clipboard, you can query what data formats are available, then if the formated text is there, you can read it by specifying the appropriate format. It would contain, for example, the RTF simbols or the HTML markup, which is then up to you to interpret.

    As an example, a few threads on StackOverflow deal with this. Two specially relevant are those:
    winforms - C# How can I paste formatted text from clipboard to the RichTextBox - Stack Overflow
    .net - Copying text along with its formatting from a RichTextBox - Stack Overflow

    While both talk about a RichTextBox control, the clipboard part is independent of it and you can use it in any situation you need. Also, be sure to read something from Wikipedia:
    Clipboard (computing - Wikipedia)

    And finally, the official .NET Framework reference on the topic, applicable to C#, as well as all .NET languages:
    Clipboard Class (System.Windows.Forms)

    I have no real experience with Java, but the fundamental concepts are the same. Its documentation will help fill the gaps and understand the differences in the APIs.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:31.
Find Us