Brick wall reached...assistance needed

Hi All!

I am writing an app in C#.
I need to be able to display text (.txt) files created by the app in dialog boxes.
I can do this in vb.net all day long, but cannot find reference for doing so in C# .NET.

If someone could please, PLEASE point me in the right direction, I would greatly appreciate it.

Thanks!
Gary


Answer this question

Brick wall reached...assistance needed

  • MichMash

    yes, just as Nata1 stated code please. I know of console apps only because the help-system insist of having the console as output device, while i'm writing solely for windows, and have to transform every sample to a windows-type application.
    I therefore haven't a clue why a TextBox should be mistaken for the console!
    to my knowledge textBox.Text = "file content" might only give some unreadible tokens in those cases where the text uses CRLF in stead of only CR which could be remidied with a simple sustitution (string.Replace(..) method)
    Transferal to the console( ) I hardly ever start applications from a console, so probably didn't notice because of this. But perhaps we spot something when we view the code.

  • thompson16

    Thanks for your response.  I am trying to use a multiline textbox control (as I did in a vb and vc++ version of the same app).  I have attempted to use the code example in vs.net, but it writes to the console, not to a textBox control.

    Any suggestions

  • Chibuzo

    This depends on the content of your dialog box, suppose a Label with enough height and width. <strong>label.Text = tekst</strong> a multiline TextBox has a <strong>Lines</strong> member which can hold an array of lines where you can scroll through if needed. Other Controls have other options.
  • Joseph Fluckiger

    Griffey could you paste some code

    why doesn't frm.TextBoxName.Text =  the contents of the text file stream

    work

  • Balascandent

    Gary, the technique should be exactly the same between VB.NET and C#, since you are using the framework libraries in both cases (unless you are using the VB compatibility library, which is another case). 

    If you are still stuck, post an example in a new thread and I'll be happy to help you figure it out.

    -Paul

  • smitaB

    Yes that darn connsole fixation of the sample writers, the code you wrote merely opens the file. now you need to read  through the file so:


    private void seeReadings() 

       string path = @"C:\readings.txt"; 

        using (StreamReader sr = new StreamReader(path)) 
       { 
             string txt = "",s;
             while ((s = sr.ReadLine()) != nulll)
                  txt += s + "\n";
              textbox.Text = txt;
       } 
    }


    The Sample (console app!) shows use of an sr.Peek() to test for the end of file, I used the while type loop above, though this might be on a TextReader. There are several options here.
    In case you want to print on other controls you might concider:
    <strong>Graphics g = control.CreateGraphics()</strong>
    and use:
    <strong>g.DrawString(....)</strong>
    to draw on that control meanwhile reading taxt from the file. I do think some experimentation of your own might be more benificial for you.

    good luck, hope this helps.

  • Samuel_zhang

    I am sorry to have seemed vague.  What I was trying to state is that the only examples of how to display text from an external file show me how to do so on the console, rather than withing a windows form.  This is the code I have set up, and is where I am stuck now.  Thanks again for all of your help on this.  I really appreciate it.

    private void seeReadings()
    {
    string path = @"C:\readings.txt";

    using (StreamReader sr = new StreamReader(path))
    {

    sr.ReadToEnd();
    }

    }

  • Brick wall reached...assistance needed