views:

111

answers:

3

I have a program that the user enters some data and then it creates a form letter and copys it to there clipboard

Some of the users came back and said they would like some parts of the letter to be underlined to help the people they are sending it to read it easier ( headlines etc)

I don't know of a way to mark something as underlined

im currently using

Clipboard.SetDataObject(sb.ToString(), true);

where sb is a string builder

Any idea on how to mark something as underlined?

+1  A: 

Assuming your users are pasting into a program that recognizes HTML (such as Microsoft Word), you can do this:

string underlinedText = "<span style=\"text-decoration: underline;\">" + 
                            sb.ToString() + "</span>";
Clipboard.SetDataObject(underlinedText, true);

This would underline the entire text snippet that is copied into the clipboard buffer.

Tim S. Van Haren
text-decoration:, not ;?
Andrew Coleson
Thanks. Fixed. :)
Tim S. Van Haren
A: 

Where are they pasting this data into? Is your code a client or web application?

I would suggest adding a WYSIWYG control or RichTextBox. This can give the user the ability to do formatting in your program before the cut and paste.

Tony Borf
More details are needed to give a proper answer
Tony Borf
+1  A: 

You may want to consider RTF as an alternative to HTML as it is older it often has better support and is more likely to end up with a proper text document rather than MS Words horrible interpretation of HTML. Also you will find RTF supports page breaks where as HTML doesn't. But be warned the mark-up in RTF is a little weird. For example:

Clipboard.SetText(@"{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}\viewkind4\uc1\pard\f0\fs20 text \ul  text\ulnone  text\par}", TextDataFormat.Rtf);

The specification for RTF can be found obtainied from Microsoft here.

Martin Brown
Do you think this would work in outlook?
Crash893
If you mean copy to clipboard in C# then paste in Outlook then yes. On reflection when I say alternative I should have put in addition as the more formats you load the clipboard up with the more likely the destination is to find one it likes.
Martin Brown