Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pasting to anbd from clipboard

Pasting to anbd from clipboard

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RomanD
    wrote on last edited by
    #1

    How to I paste text to and from clipboard while preserving the formating. Because when I paste from the clipboar, the text that use to be bol is not, etc... Say from 1 textbox into another. Or from a textbox into a word document. Thanks

    N 1 Reply Last reply
    0
    • R RomanD

      How to I paste text to and from clipboard while preserving the formating. Because when I paste from the clipboar, the text that use to be bol is not, etc... Say from 1 textbox into another. Or from a textbox into a word document. Thanks

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      I would suggest you read through the Clipboard Class[^]. - Nick Parker
      My Blog | My Articles

      L 1 Reply Last reply
      0
      • N Nick Parker

        I would suggest you read through the Clipboard Class[^]. - Nick Parker
        My Blog | My Articles

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        I got it to copy, my question is that why it still looses format. Storing Info: IDataObject d = Clipboard.GetDataObject(); //d.SetData(DataFormats.Rtf, true, richTextBox1.Text); // d.SetData(DataFormats.Rtf, richTextBox1.Rtf); Clipboard.SetText(richTextBox1.Text, TextDataFormat.Rtf); Retriving info: foreach (Word.Shape bkMark in aDoc.Shapes) { if (bkMark.TextFrame.TextRange.Text.Contains("heading")) { // bkMark.TextFrame.TextRange.Paste(); bkMark.TextFrame.TextRange.Text = Clipboard.GetText(TextDataFormat.Rtf).ToString(); //Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); // // } }

        M 1 Reply Last reply
        0
        • L Lost User

          I got it to copy, my question is that why it still looses format. Storing Info: IDataObject d = Clipboard.GetDataObject(); //d.SetData(DataFormats.Rtf, true, richTextBox1.Text); // d.SetData(DataFormats.Rtf, richTextBox1.Rtf); Clipboard.SetText(richTextBox1.Text, TextDataFormat.Rtf); Retriving info: foreach (Word.Shape bkMark in aDoc.Shapes) { if (bkMark.TextFrame.TextRange.Text.Contains("heading")) { // bkMark.TextFrame.TextRange.Paste(); bkMark.TextFrame.TextRange.Text = Clipboard.GetText(TextDataFormat.Rtf).ToString(); //Clipboard.GetDataObject().GetData(DataFormats.Text).ToString(); // // } }

          M Offline
          M Offline
          mav northwind
          wrote on last edited by
          #4

          bkMark.TextFrame.TextRange.Text contains plain text by definition, if you want formatted text you'll have to use clipboard pasting. To have control over what will actually get pasted you'll have to specify that you want RTF. IIRC there's a PasteSpecial (or something similar) where you can tell Word what format to paste. Regards, mav

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups