Windows Develop Bookmark and Share   
 index > Windows Forms General > in Immeidate window it works but not on class- RTF-clipborad
 

in Immeidate window it works but not on class- RTF-clipborad

Hi All,

I've a very simple problem. When i convert simple text into RTF in a class it doesnt work but whne I see the result in immeidate window I'm able to see the actual result. Why is this difference? Please see the below code and its very simple and starightforward but I'm struggling to findout the root cause.

Dim objData As New DataObject(strText)

Clipboard.SetDataObject(objData)

Dim reverdata As New DataObject

reverdata = Clipboard.GetDataObject()

'now get the new object

If Not reverdata Is Nothing Then

strRichText = reverdata.GetData("Rich Text Format", True)

End If

when i see the value of reverdata.GetData("Rich Text Format", True) in immediate window I'm able to see RTF string but when I run the program I get nothing in strRichText variable.

Any thoughts? I'm using 1.1 framework.

Cheers,

Rama

Rama Boya  Thursday, November 23, 2006 6:34 PM
It's pretty amazing you can see RTF in the Immediate window, the clipboard is not automagically going to convert plain text to RTF. Another way to do it is to use a RichTextBox to do the conversion for you. For example:

public static string ConvertText2Rtf(string txt) {
using (RichTextBox rtb = new RichTextBox()) {
rtb.Text = txt;
return rtb.Rtf;
}
}

nobugz  Friday, November 24, 2006 2:06 PM

Hi All,

Can anyone help me?

Rama Boya  Friday, November 24, 2006 9:31 AM
It's pretty amazing you can see RTF in the Immediate window, the clipboard is not automagically going to convert plain text to RTF. Another way to do it is to use a RichTextBox to do the conversion for you. For example:

public static string ConvertText2Rtf(string txt) {
using (RichTextBox rtb = new RichTextBox()) {
rtb.Text = txt;
return rtb.Rtf;
}
}

nobugz  Friday, November 24, 2006 2:06 PM

Hi nobugz,

Thanks a lot. its working fine.

Cheers,

Rama

Rama Boya  Friday, November 24, 2006 3:07 PM

You can use google to search for other answers

Custom Search

More Threads

• How would I create a control that looks like this?
• [C#]Using Backgroundworker in a separate class
• SaveFileDialog path for a CD drive question
• Blank space in menu item
• font
• Master Page equivalent (newbie)
• String Fuction
• How to get the Systems Names which are available in the network?
• How to permanently change the highlighted items' colors in the ListBox?
• Windows vista installation problem.