469,282 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

newline format control in richtextbox

I can't seem to add a newline (/n) to get a richtextbox control to display text on successive lines. The text that I type is overwritten. How do I remedy this

My example

richTextBox->Multiline = true
richTextBox->Text = S"First line /n"
richTextBox->Text = S"Second line"

Thanks

DAS
Nov 17 '05 #1
10 11315
Hi,

Try using \r\n - sounds like you're just getting a carriage return, and not
a newline.

Steve

"D Steward" <an*******@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
I can't seem to add a newline (/n) to get a richtextbox control to display text on successive lines. The text that I type is overwritten. How do I
remedy this?
My example:

richTextBox->Multiline = true;
richTextBox->Text = S"First line /n";
richTextBox->Text = S"Second line";

Thanks,

DAS

Nov 17 '05 #2
I have tried numerous combinations of escape sequences, and none of them work

It appears what happens is that it doesn't recognize the escape sequence and just overwrites the previous line

Any suggestions would be appreciated

DAS
Nov 17 '05 #3
Also use the += operator. Otherwise you're just overwriting the
previous string.

Austin

On Fri, 30 Jan 2004 12:43:37 -0000, "Steve McLellan"
<sj*@fixerlabs.com.NOSPAM> wrote:
Hi,

Try using \r\n - sounds like you're just getting a carriage return, and not
a newline.

Steve

"D Steward" <an*******@discussions.microsoft.com> wrote in message
news:A8**********************************@microso ft.com...
I can't seem to add a newline (/n) to get a richtextbox control to display

text on successive lines. The text that I type is overwritten. How do I
remedy this?

My example:

richTextBox->Multiline = true;
richTextBox->Text = S"First line /n";
richTextBox->Text = S"Second line";

Thanks,

DAS


Nov 17 '05 #4
I tried this to no avail. Could you give me an example of how I could modify my originally posted code

Thanks

DA

----- Austin Ehlers wrote: ----

Also use the += operator. Otherwise you're just overwriting th
previous string

Austi

On Fri, 30 Jan 2004 12:43:37 -0000, "Steve McLellan
<sj*@fixerlabs.com.NOSPAM> wrote
Hi
Try using \r\n - sounds like you're just getting a carriage return, and no

a newline
Stev
"D Steward" <an*******@discussions.microsoft.com> wrote in messag

news:A8**********************************@microso ft.com..
I can't seem to add a newline (/n) to get a richtextbox control to displa

text on successive lines. The text that I type is overwritten. How do
remedy this
My example
richTextBox->Multiline = true

richTextBox->Text = S"First line /n"
richTextBox->Text = S"Second line"
Thanks
DA

Nov 17 '05 #5
=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote:
It appears what happens is that it doesn't recognize the escape
sequence and just overwrites the previous line.


You're not using an escape sequence, that's why :-)

"/n" vs. "\n"
--
harry
Nov 17 '05 #6
=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote:
You are correct that this was not an escape sequence as I mistakenly
wrote it here. It is written correctly in my program, however as "\n".
This still doesn't solve the problem. Austin Ehlers added that I
should use += somewhere, but where? This should not be an
extraordinarily difficult problem in a richtextbox control, but
appears to be difficult indeed.


Okay, we got the escape thing out of the way then.

If these next two lines are what you have in your program...

richTextBox->Text = S"First line /n";
richTextBox->Text = S"Second line";

....then we see that the second line is assigning a new string to the Text
property, which overwrites the effects of the first line. The second line
should use '+=' in order to append text instead of overwriting it.

--
harry
Nov 17 '05 #7
Harry

I assume that you mean

richTextBox->Text = S"First line /n"
richTextBox->Text += S"Second line"

I tried this and it doesn't compile because it is a managed object where pointer arithmetic is not allowed

DA

----- harry_bosch wrote: ----

=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote
You are correct that this was not an escape sequence as I mistakenl
wrote it here. It is written correctly in my program, however as "\n"
This still doesn't solve the problem. Austin Ehlers added that
should use += somewhere, but where? This should not be a
extraordinarily difficult problem in a richtextbox control, bu
appears to be difficult indeed.


Okay, we got the escape thing out of the way then

If these next two lines are what you have in your program..

richTextBox->Text = S"First line /n"
richTextBox->Text = S"Second line"

....then we see that the second line is assigning a new string to the Text
property, which overwrites the effects of the first line. The second line
should use '+=' in order to append text instead of overwriting it

--
harr

Nov 17 '05 #8
=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote:
Harry,

I assume that you mean:

richTextBox->Text = S"First line /n";
richTextBox->Text += S"Second line";

I tried this and it doesn't compile because it is a managed object
where pointer arithmetic is not allowed.


Hmm, too much native C++ for me lately :-) This is managed code, so String
is immutable. I would then use StringBuilder to create the complete string,
and then assign it to the Text property (if, for instance, in your real
system you are doing more than just these two short lines).

I haven't checked the syntax on this, but you could also just assign to
Text the concatenation of its current value with the new text you want to
append. Something like:

richTextBox->Text = richTextBox->Text + S"Second line";

I would opt for a StringBuilder, however, instead of this, unless testing
has shown that the difference is negligible.

A quick look in the .NET docs shows that RichTextBox (via its base class)
has a Lines property, which allows you to assign lines to a multiline
control by index. Then you could do something like:

richTextBox->Lines[0] = S"My first line";
richTextBox->Lines[1] = S"My second line";

I've never used these classes, so the above is completely untested.

--
harry
Nov 17 '05 #9
Harry,

Thanks for the help. However, I found another route that works fine. Instead of using richTextBox1->Text ... I use richTextBox1->AppendText( S"\n First line \n second line"). This works fine for me.

So, now I go on with my project.

DAS

----- harry_bosch wrote: -----

=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote:
Harry,
I assume that you mean:
richTextBox->Text = S"First line /n";

richTextBox->Text += S"Second line";
I tried this and it doesn't compile because it is a managed object

where pointer arithmetic is not allowed.


Hmm, too much native C++ for me lately :-) This is managed code, so String
is immutable. I would then use StringBuilder to create the complete string,
and then assign it to the Text property (if, for instance, in your real
system you are doing more than just these two short lines).

I haven't checked the syntax on this, but you could also just assign to
Text the concatenation of its current value with the new text you want to
append. Something like:

richTextBox->Text = richTextBox->Text + S"Second line";

I would opt for a StringBuilder, however, instead of this, unless testing
has shown that the difference is negligible.

A quick look in the .NET docs shows that RichTextBox (via its base class)
has a Lines property, which allows you to assign lines to a multiline
control by index. Then you could do something like:

richTextBox->Lines[0] = S"My first line";
richTextBox->Lines[1] = S"My second line";

I've never used these classes, so the above is completely untested.

--
harry

Nov 17 '05 #10
=?Utf-8?B?RCBTdGV3YXJk?= <an*******@discussions.microsoft.com> wrote:
Thanks for the help. However, I found another route that works fine.
Instead of using richTextBox1->Text ... I use
richTextBox1->AppendText( S"\n First line \n second line"). This works
fine for me.


Glad to hear it. I missed that one -- I guess reading the docs really does
pay off, huh? :-)
--
harry
Nov 17 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by CNU | last post: by
29 posts views Thread by runningdog | last post: by
4 posts views Thread by AWesner | last post: by
11 posts views Thread by John J. Hughes II | last post: by
3 posts views Thread by iwdu15 | last post: by
7 posts views Thread by Tom | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.