To COPY a string into the clipboard ...

  • Thread starter Thread starter Hariharan Subramony
  • Start date Start date
H

Hariharan Subramony

Hello Guys,

I have an important issue and need solution at the earliest. Thanks in
advance.

I have a RichTextBox named say, ' rtb' that has the text "Hello, I am fine."

To place it in the clipboard, I just have to use the following command.

rtb.Copy(); so that, I can paste the copied text into wherever I like. Now,
after copying, I wanted to prepend a text say, "Great"; but this text does
not appear in the RichTextBox. So, I can't use the 'Copy()' command as the
text is just a string object. But, I want that string object be prepended to
or somehow copied to the clipboard (NOTE: the text "Great" does not appear
in the RichTextBox). Is there any way to go about it? I also, want to append
a ' \n ' at the end.

Hope, you understood what I mean. This is very important for me and I am
struck at this for a very long time. Would be really grateful, if someone
could assist me in getting this work at the earliest. Once again, thanks a
lot in advance. Let me ( (e-mail address removed) ) know, if you have any
questions.

Regards,
Hariharan S
 
Hariharan Subramony said:
Hello Guys,

I have an important issue and need solution at the earliest. Thanks in
advance.

I have a RichTextBox named say, ' rtb' that has the text "Hello, I am fine."

To place it in the clipboard, I just have to use the following command.

rtb.Copy(); so that, I can paste the copied text into wherever I like. Now,
after copying, I wanted to prepend a text say, "Great"; but this text does
not appear in the RichTextBox. So, I can't use the 'Copy()' command as the
text is just a string object. But, I want that string object be prepended to
or somehow copied to the clipboard (NOTE: the text "Great" does not appear
in the RichTextBox). Is there any way to go about it? I also, want to append
a ' \n ' at the end.

You want to copy text that is not in a RichTextBox but in a
string variable, right? Use the Clipboard class:

string myString = "Great";
Clipboard.SetDataObject( myString, true );

That's all! Hope this helps.

Markus
 
Hariharan Subramony said:
Hello Guys,

I have an important issue and need solution at the earliest. Thanks in
advance.

I have a RichTextBox named say, ' rtb' that has the text "Hello, I am fine."

To place it in the clipboard, I just have to use the following command.

rtb.Copy(); so that, I can paste the copied text into wherever I like. Now,
after copying, I wanted to prepend a text say, "Great"; but this text does
not appear in the RichTextBox. So, I can't use the 'Copy()' command as the
text is just a string object. But, I want that string object be prepended to
or somehow copied to the clipboard (NOTE: the text "Great" does not appear
in the RichTextBox). Is there any way to go about it? I also, want to append
a ' \n ' at the end.

Have a look at Clipboard.SetDataObject - if you call it with
"Great "+rtb.Text+"\n" as the parameter, that should be okay - but it
will only put the straight text on the clipboard, not the rich text -
at least, that's my suspicion. (I've only checked that putting text in
with SetDataObject works.)
 
Back
Top