TextBox / IO

  • Thread starter Thread starter Paddy
  • Start date Start date
P

Paddy

I am reading a file like so:

using(FileStream inStream = new FileStream
("addresses",FileMode.Open,FileAccess.Read))
{
}

One of the strings is long and is displayed
in a multil;ine textbox.

When I do that carriage returns in the multiline text
box do not produce the desired result, neither does
using keypress and inserting "\r\n" at the cursor position
when enter is pressed.

Please assist.
 
Hi Paddy,

I'm not quite sure what you mean. A multiline textbox should support line breaks just fine. Manually or programmatically. WordWrap can be turned true or false, but these shouldn't interfere with breaking the lines on your own.
 
Hi Morten,

If I enter something in the textbox (re my original posting please)
and finish off by punching the "enter" key - then write to file,

then subsequently reading the record shows nothing at all in the
textbox concerned. So I am at a loss as to what is happening.

Paddy.



Morten Wennevik said:
Hi Paddy,

I'm not quite sure what you mean. A multiline textbox should support line
breaks just fine. Manually or programmatically. WordWrap can be turned true
or false, but these shouldn't interfere with breaking the lines on your own.
 
Hi Paddy,

If you write in a single line textbox, hitting [ENTER] will not add a carriage return. However, if you also write in a multiline textbox then any [ENTER] you do will be saved with the rest of the text.

If you use a single line textbox, you can add your own \r\n whenever you hit [ENTER] using the KeyPress event

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)13) // 13 is the code for the carriage return
{
textBox1.Text += "\r\n"; // add cr and lf to the string
textBox1.SelectionStart = textBox1.TextLength; // move the cursor to the end
}
}
 
Hi Morten,

I do have a multi line textbox,
if I do [ENTER] + additional text
the additional text is lost, i.e., not written.

I did already try

if(e.KeyChar == (char)13)
{
textBox1.Text += "\r\n";
}

That doesn't do the trick either.

I am working with an inherited form, maybe that
is a cause?

Paddy

Morten Wennevik said:
Hi Paddy,

If you write in a single line textbox, hitting [ENTER] will not add a
carriage return. However, if you also write in a multiline textbox then any
[ENTER] you do will be saved with the rest of the text.
If you use a single line textbox, you can add your own \r\n whenever you
hit [ENTER] using the KeyPress event
private void textBox1_KeyPress(object sender,
System.Windows.Forms.KeyPressEventArgs e)
 
It is possible that the parent interferes somehow, but I'm afraid I am out of ideas. :(
You might want to try again writing a new message (messages more than a day old tends to be "forgotten") and if you could provide more details, code etc, it might help.
 
Back
Top