Results 1 to 17 of 17

Thread: [RESOLVED] Copy RTF to Clipboard, but it will not paste to notepad

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Resolved [RESOLVED] Copy RTF to Clipboard, but it will not paste to notepad

    If I copy my richtext from the richtextbox, it will paste into wordpad just fine,
    but it will not send the text to notepad. If I take wordpad and copy richtext from it, it
    will paste into notepad just fine . . . so what am I missing?

    Code:
    Clipboard.SetText(RTBMain.SelectedRtf, TextDataFormat.Rtf)
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    I don't know why it's not working for you, but:

    Option Strict On
    Option Explicit On
    Public
    Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim str AsString = RichTextBox1.SelectedRtf
    Clipboard.SetText(str, TextDataFormat.Rtf)
    End Sub
    End Class

    works for me.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Notepad is a plain text editor, Wordpad is a rich text editor. See my signature!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    All well and good . . . however . . . open up wordpad, type some text, then copy it and paste it into notepad . . . it works . . . so,
    it should be possible to make it work in any application . . . .
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    If I open up wordpad, type "some text" with the font set up as:
    • Consolas
    • 28
    • bold
    • italic
    • underline
    copy that text from wordpad to notepad, "some text" get's copied in plain text. Is that what you're wanting?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Quote Originally Posted by dday9 View Post
    I don't know why it's not working for you, but:

    Option Strict On
    Option Explicit On
    Public
    Class Form1
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim str AsString = RichTextBox1.SelectedRtf
    Clipboard.SetText(str, TextDataFormat.Rtf)
    End Sub
    End Class

    works for me.
    Copied to Note Pad without a problem
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Copied to Note Pad without a problem
    Yes, because of the assignment to a string. You can't copy the selection directly to the clipboard as rich text format and paste into notepad (irrespective of what the font is or whether there is any actual rich text content, incidentally!) Them's just the 'rules'. When you copy from wordpad using the standard Windows procedure it defaults to plain text unless using the special paste formats available in Word, for example. When you send rtf from the rtb direct to the clipboard it goes as an object that looks like this ....

    {\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
    \uc1\pard\f0\fs17 hello and welcome}

    .... (that's what you get if you send it as plain text, by the way) which Notepad simply cannot interpret but Wordpad is designed to do. Like I said. Rocket Science it ain't.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    If I open up wordpad, type "some text" with the font set up as:
    •Consolas
    •28
    •bold
    •italic
    •underline
    copy that text from wordpad to notepad, "some text" get's copied in plain text. Is that what you're wanting?
    Yes, that is what I want.

    Dim str AsString = RichTextBox1.SelectedRtf
    Clipboard.SetText(str, TextDataFormat.Rtf)


    Does not make it happen. What I am trying to figure out is how the RTF seems to
    get changed to normal text, so when I copy the text in my application that has
    all RTF, it automatically pastes the result into a non-rtf textbox with only the
    text, not all the rtf formatting included. Wordpad to notepad does it. If you
    color text in Wordpad, and paste it into notepad, it goes just fine, it strips
    off the color and all the other formatting, and that is exactly what I want it to do.
    Last edited by skywola; Nov 23rd, 2012 at 01:16 PM.
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Quote Originally Posted by skywola View Post
    Yes, that is what I want.

    Dim str AsString = RichTextBox1.SelectedRtf
    Clipboard.SetText(str, TextDataFormat.Rtf)


    Does not make it happen.
    Nope, you're right it doesn't!

    Clipboard.SetText(RTBMain.SelectedText)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    I am guessing that you have changed something in the selected text, like color. In that case I don't think a paste into note pad will work.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    My guess is that it has something to do with the IDataObject, but I have not quite discovered how to make it work.
    It can be done, I have no doubt in my mind, it is just going to be a matter of getting the code right. I suspect that
    it is something that is done when the copy function is invoked, that stores the thing copied into multiple formats.
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  12. #12
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    I refer the honourable member to the answer I gave some moments ago!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Ahhh, that works just fine, dunfiddlin, but try posting it into Wordpad now . . . . all you get is the text, no color.
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  14. #14
    Frenzied Member
    Join Date
    Jul 2011
    Location
    UK
    Posts
    1,335

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    @skywola: I think you are totally correct in Post #11.

    Code:
    Clipboard.Clear()
    
    Dim data As New DataObject()
    data.SetData(DataFormats.Text, RichTextBox1.SelectedText)
    data.SetData(DataFormats.Rtf, RichTextBox1.SelectedRtf)
    
    Clipboard.SetDataObject(data)
    More info here

  15. #15
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Quote Originally Posted by skywola View Post
    Ahhh, that works just fine, dunfiddlin, but try posting it into Wordpad now . . . . all you get is the text, no color.
    Well you can't have it both ways! Either it's rich text in which case it goes into Wordpad but not Notepad or it's plain text in which case it goes into Notepad and Wordpad but as the plain text that it is. If you want the option then you'll have to program some way of determining the intended target ahead of time or of giving the user the option.

    Edit: or read Inferrd's post apparently!
    Last edited by dunfiddlin; Nov 23rd, 2012 at 02:50 PM.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    Arizona
    Posts
    185

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Dunfiddlin . . . Don't tell me I can't do it, or Inferrd will prove you wrong . . . .

    Inferrd . . . that is a great solution, worked like a charm. Thanks! +REP to you . .

    I like to paste code and other things into notepad sometimes, and this gets the job done!
    .
    We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
    GENE RODDENBERRY
    .
    http://www.tachufind.com
    .

  17. #17
    New Member
    Join Date
    Nov 2021
    Posts
    1

    Re: Copy RTF to Clipboard, but it will not paste to notepad

    Helo Friend
    I d not know whether you are going to read this or not. But still I need to say some thing.

    Your code is only one code that worked for me.

    Thanks a lot
    Sen

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width