Drarig29
Drarig29

Reputation: 2245

Dynamically paste Visual Studio styled code in a RichTextBox

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 :

enter image description here

Result when I do it dynamically :

enter image description here

I've tried using RichTextBox1.Text = My.Computer.Clipboard.GetText(TextDataFormat.Rtf), but it doesn't work too :

enter image description here

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

Answers (1)

LarsTech
LarsTech

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

Related Questions