"line break" disapears in text box after resizing the form

P

Philip.Arbin

I put a text box on a form and set it to "multi line".
I use it to show some log information.

Every time there is some information, I use TextBox.AppendText method to add
a information string and a "\n" into the text box. There will be a line
break after the infromation string for the "\n" charactor.

But after i resized the form or click some other window on the task bar and
switch back, the line break disapears. All the text turns into only one
single line.
Is there something wrong using "\n" in multiline text box?
Is there any solution for this issue? or I should use richtextbox or detail
listview instead?
 
L

Linda Liu [MSFT]

Hi,

Thank you for posting.

I have created a simple WinForm project containing a form for testing. I
put a textbox and a button on the form and set the MultiLine property of
the textbox to True. I added an event handler for the button's click
event. In the button's click event I used the AppendText() method of the
textbox to add a string into the textbox. I used a "\n" to add a line break
and there was a line break for the "\n" charactor. However I didn't see
the problem that the line break disappeared and the text in the textbox
turned into only one single line after I resized the form or clicked some
other window on the task bar and switched back. The line break still
existed.

Maybe you could have a try to use "\r\n" to add a line break.

Hope this is helpful to you.
If you have any other concerns or need anything else, please don't hesitate
to tell me.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
P

Philip.Arbin

I tried it again and found it happens under this condition:

-- if the textbox's "anchor" propertise is set to "left, top, right";

then i realize that this will happen when you resize the textbox, not the
form.

And i tried the "\r\n", it works.

thank you very much.
 
L

Linda Liu [MSFT]

Hi Philip,

You're welcome!
If you have any other questions or concerns, please do not hesitate to
contact us. It is always our pleasure to be of assistance.



Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top