Hack Forums
[.NET] [VB.NET] Add text file text to richtextbox. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB.NET] Add text file text to richtextbox. (/showthread.php?tid=118406)



[VB.NET] Add text file text to richtextbox. - BETAhkr - Aug 7, 2009

This will allow you to browse and select a text file on your computer
and have the text put right into a textbox or richtextbox
on your program.

Just open a richtextbox, A command button, And 1 Openfiledialog.

[IMG]http://i30.[censored].com/2md1bvt.jpg[/IMG]

Put this code in after double clicking on the command button.

Code
OpenFileDialog1.ShowDialog()
        Dim fname As String = OpenFileDialog1.FileName
        If System.IO.File.Exists(fname) Then
            Dim read As New System.IO.StreamReader(fname)
            RichTextBox1.Text = read.ReadToEnd
            read.Close()
        Else
            MsgBox("Error: File does not exists, Please choose another")
        End If
    End Sub

[IMG]http://i25.[censored].com/aywtwz.jpg[/IMG]

You can now test out your program.
You will see that when you click on your command put
where you put the code in, you can browse and select a text file
off your computer to be added into the programs Richtextbox1.

[IMG]http://i30.[censored].com/34pjptw.jpg[/IMG]

Once you select which text file you would like
Double click on the text file or highlight the text
file you would like and click "Open" on the browser.
You will then see your text go into the richtextbox on the program
and you will be able to scroll through all of it and read it.
This is good for having "How to use" text files that come with your program, Since no one ever really opens the read me.txt or the how to use.txt
now you can add the choice right into the program incase
they eventually need to read it.

[IMG]http://i28.[censored].com/117wjft.jpg[/IMG]


- Xx1232shooterxX - Aug 7, 2009

This will be useful to me thanks.


- What Rights - Aug 7, 2009

Thats spiffy. Could be useful for numerous things.


- BETAhkr - Aug 7, 2009

You are very much welcome.
And yes, I used this method in several projects, Happens to be a great code.
Enjoy it.


* - Sud0x3 - Sep 17, 2009

(Aug 7, 2009 09:03 PM)1232shooter Wrote:  This will be useful to me thanks.



* - Romeo. - Sep 17, 2009

I love your tutorials, not too advenced, but realy greats !

I already know this, but don't mind to see again !


* - BETAhkr - Sep 17, 2009

I don't like to make my tutorials advanced, I like to show the noobs how to step there game up.