473,246 Members | 1,466 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,246 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 11567
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: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.