Reputation: 2245
I'd like to dynamically paste Visual Studio styled/formatted code (with the font colors) in a RichTextBox.
It only works when I paste the code at Runtime as a user (using Ctrl+V
in the RichTextBox) but not when I use this code RichTextBox1.Text = My.Computer.Clipboard.GetText()
.
Result when I do it manually :
Result when I do it dynamically :
I've tried using RichTextBox1.Text = My.Computer.Clipboard.GetText(TextDataFormat.Rtf)
, but it doesn't work too :
So, how can I paste the text dynamically to get the same result as when I paste it manually ?
PS : The full code I'm using is in the screenshots ;)
Regards, Drarig29.
Upvotes: 1
Views: 206
Reputation: 81645
The Text property of the RichTextBox control does not do formatting, so try using the Rtf property instead:
RichTextBox1.Rtf = My.Computer.Clipboard.GetText(TextDataFormat.Rtf)
Upvotes: 1