Style contagion in a TextArea

To allow you to see the annoyance, I create a brand new project.

I put a TextArea, a PushButton.

Code in PushButton1.Action:

[code] Dim Clip As New Clipboard

If Clip.TextAvailable Then
TA.Text = “”

TA.Text = Clip.Text

Clip.Close

End If[/code]

At run time, place a Red / Bold text (two words are enough) in the TextArea (using Copy / Paste).

Place the cursor inside the red text, place a 10 or so lines of styled (or unstyled) text in the Clipboard and press in the PushButton.

Now all of your Text is in Bold / Red.

How can I get rid of that ?

Nota: this happens in a software when I read raw text and place it into a TextArea. The text is auto-saved to disk (fortunately as REW TEXT).

Question: is this a bug to report ?

BTW: after a little sleep, I awoke with a solution. Every time I change the TextArea whole contents, I have first to clear it, then set the color, text font name & size, etc. to reset the TextArea to a default state to avoid this annoyance.

Note: this phenomen can be seen wherever the cursor is in the TextArea (not only at position 2…), provided it is in a style that is not the default style.

Dim s As String = Clip.Text
TA.Text = s

Thank you for your answer Jym, but how the answer can change the bad behavior ?

The problem is not how I fill the TextArea with text, but ho I avoid the textArea to keep the previous styles on my new text.

That is because I added:
TA.Text = “”

before pasting text to the TextArea.

That is why I wrote:
“Nota: this happens in a software when I read raw text and place it into a TextArea. The text is auto-saved to disk (fortunately as RAW TEXT).”.

Norman gaves me an idea (advice solution for a different problem): continue to use a TextArea, but uncheck the Styles property for it (since I cannot use it - now).

I will investigate (for these two cases, but I have a case where I need the styles and I have troubles with, but I am not ready to ask question or use Feedback for that).

It’s not bad behaviour. If you were looking for Clip.StringValue, (which isn’t a property) then it would be bad behaviour. You’re asking to place Text which would imply that you are also asking for the style(s) as well. You need to control how Text is going to look on a TextArea just like you would have to click the appropriate button on MS Word for pasting in Paste Options, ‘Keep Text Only’, ‘Match Text’ …

I used the Clipboard example only because it is easier to display the wrong feature.

You can get the same behaviour using TextInputStream.

And if I set the TextArea to Styled = OFF, I get the same result.