By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

StreamWriter Class Question...

P: n/a
I am trying to pass a text stream from streamwriter class to a richtextbox,
or textbox doesn't matter which one. I have the file write version working
fine such as:

x.streamwriter = System.IO.File.CreateText("C:\text.txt")
Anyway to write to a textbox or rtf rather than file... ?

Thanks in advance...

Anthony Nystrom
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Use a StringWriter instead of a StreamWriter. StringWriter has a
ToString() method you can call to set the text in the textbox.

textBox.Test = stringWriter.ToString()

You can't bind a StringWriter to a TextBox though--you have to set the
TextBox.Text property manually. You can create a custom writer class
that adds a binding enabled Text property and then you can bind your
custom class to a TextBox (I think you just need a Text property and a
TextChanged event).

If the underlying function needs to work with both a StreamWriter and
a StringWriter, then declare the property/argument/variable as type
TextWriter.

HTH,

Sam
On Thu, 30 Dec 2004 20:33:01 -0800, Anthony Nystrom
<An************@discussions.microsoft.com> wrote:
I am trying to pass a text stream from streamwriter class to a richtextbox,
or textbox doesn't matter which one. I have the file write version working
fine such as:

x.streamwriter = System.IO.File.CreateText("C:\text.txt")
Anyway to write to a textbox or rtf rather than file... ?

Thanks in advance...

Anthony Nystrom


Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.