473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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 11588
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vanvee | last post by:
Hi I have a user control that contains a RichTextBox in vb.net. In my program, I create multiple instances of this control (with the RichTextBox being in each one), that appear one above the...
1
by: CNU | last post by:
Hi, I have a richtextbox control that displays some xml data either by loading from a file or by copy-paste in plaintext format. So, it is displayed without any formatting or indentation. Now,...
4
by: Du | last post by:
I want to format the text within my richtextbox. However I have large amount of text to change, simply using richtextbox.select and format is not pratical. How do I change text format using...
1
by: TheBinar | last post by:
Hi I have a user control that contains a RichTextBox in vb.net. In my program, I create multiple instances of this control (with the RichTextBox being in each one), that appear one above the...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
4
by: AWesner | last post by:
For readability sake I’m going to first state that: LF = Line Feed CHR(10) CR = Carriage Return CHR(13) Since Rich Text Format is a standard formalized by Microsoft Corporation I get to ask...
11
by: John J. Hughes II | last post by:
I have a DataGridView displaying data from a DataSet. To the right of that I have a custom user control which displays one of the data set fields. The custom user control is bound to the data set...
3
by: iwdu15 | last post by:
hi, i have a control that inherits from RichTextBox. What i want to be able to do is surpress the Enter key inserting a newline into the text. For instance, in AIM when you press Enter, it doesnt...
7
by: Tom | last post by:
Hi all, I am looking for a smart way to assure a file is indeed a text file within a C# method and not binary. For example: Will "thisMysteryFile.dat" be legible if opened in a RichTextBox...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.