-
Nov 23rd, 2012, 10:09 AM
#1
Thread Starter
Addicted Member
[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
.
-
Nov 23rd, 2012, 10:54 AM
#2
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.
-
Nov 23rd, 2012, 11:42 AM
#3
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!
-
Nov 23rd, 2012, 12:13 PM
#4
Thread Starter
Addicted Member
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
.
-
Nov 23rd, 2012, 12:25 PM
#5
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?
-
Nov 23rd, 2012, 12:43 PM
#6
Re: Copy RTF to Clipboard, but it will not paste to notepad
Originally Posted by dday9
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
-
Nov 23rd, 2012, 12:55 PM
#7
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!
-
Nov 23rd, 2012, 12:58 PM
#8
Thread Starter
Addicted Member
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
.
-
Nov 23rd, 2012, 01:15 PM
#9
Re: Copy RTF to Clipboard, but it will not paste to notepad
Originally Posted by skywola
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!
-
Nov 23rd, 2012, 01:15 PM
#10
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.
-
Nov 23rd, 2012, 01:26 PM
#11
Thread Starter
Addicted Member
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
.
-
Nov 23rd, 2012, 01:29 PM
#12
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!
-
Nov 23rd, 2012, 01:35 PM
#13
Thread Starter
Addicted Member
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
.
-
Nov 23rd, 2012, 01:37 PM
#14
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
-
Nov 23rd, 2012, 02:47 PM
#15
Re: Copy RTF to Clipboard, but it will not paste to notepad
Originally Posted by skywola
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!
-
Nov 23rd, 2012, 03:43 PM
#16
Thread Starter
Addicted Member
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
.
-
Nov 30th, 2021, 11:47 PM
#17
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|