StreamWriter Class Question...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top