Results 1 to 6 of 6

Thread: Add texts to a RichtextBox with file load

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question Add texts to a RichtextBox with file load

    Is there a way to add texts before a RichTextBox file load? Here's my situation. I have a string variable that holds a bunch of data in it. Below is how I load the file into the RichTextBox.
    Code:
    richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText)
    However, I want to add the string variable to the RichTextBox along with the data that comes from the file load. Another word, I want to combine the two and store into one richtextbox. Is there a way to do this?

    Any help is greatly appreciated!

    ljCharlie

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Uh, combing a string and text file into 1 textbox?

    Just make the textbox equal to the string either before you load the text, then when you load the text do something like textbox.text += and then the code to load the file.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    Thank you very much for the suggestion. Here's what I have.

    Code:
    richtextbox1.text = strVariable
    richtextbox1.text += richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText)
    But still doesn't work. There is a blue underline on this line richTextBox1.LoadFile(filePath & strFileName, RichTextBoxStreamType.RichText)

    ljCharlie

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you could try this ...
    VB Code:
    1. [Color=Blue]Dim[/COLOR] strText [Color=Blue]As[/COLOR] [Color=Blue]String[/COLOR] = "some text" & Environment.NewLine [Color=Green]'///[/COLOR] [Color=Green]add[/COLOR] [Color=Green]newline[/COLOR] [Color=Green]if[/COLOR] [Color=Green]you[/COLOR] [Color=Green]want[/COLOR] [Color=Green]the[/COLOR] [Color=Green]string[/COLOR] [Color=Green]a[/COLOR] [Color=Green]line[/COLOR] [Color=Green]above[/COLOR] [Color=Green]the[/COLOR] [Color=Green]loaded[/COLOR] [Color=Green]file.
    2. [/COLOR]        [Color=Blue]With[/COLOR] RichTextBox1
    3.             .LoadFile("C:\test.txt", RichTextBoxStreamType.PlainText) [Color=Green]'///[/COLOR] [Color=Green]first[/COLOR] [Color=Green]load[/COLOR] [Color=Green]the[/COLOR] [Color=Green]file.
    4. [/COLOR]            .SelectionStart = 0 [Color=Green]'///[/COLOR] [Color=Green]go[/COLOR] [Color=Green]to[/COLOR] [Color=Green]beginning[/COLOR] [Color=Green]of[/COLOR] [Color=Green]text[/COLOR] [Color=Green]in[/COLOR] [Color=Green]richtextbox.
    5. [/COLOR]            .SelectedText = strText [Color=Green]'///[/COLOR] [Color=Green]then[/COLOR] [Color=Green]add[/COLOR] [Color=Green]the[/COLOR] [Color=Green]other[/COLOR] [Color=Green]string[/COLOR] [Color=Green]to[/COLOR] [Color=Green]the[/COLOR] [Color=Green]beginning.
    6. [/COLOR]            .SelectionStart = .TextLength [Color=Green]'///[/COLOR] [Color=Green]then[/COLOR] [Color=Green]back[/COLOR] [Color=Green]to[/COLOR] [Color=Green]the[/COLOR] [Color=Green]end[/COLOR] [Color=Green]of[/COLOR] [Color=Green]the[/COLOR] [Color=Green]text[/COLOR] [Color=Green]in[/COLOR] [Color=Green]richtextbox.
    7. [/COLOR]        [Color=Blue]End[/COLOR] [Color=Blue]With[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    You should post error messages when you get them.

    This is a bit hard when VS.NET isn't in front of me, but you could always load into a richtextbox that you make with code, make the string equal to your textbox and lod the other file into the textbox made with code, then use richtextbox1 += richtextbox2

    If you're loading a file with the richtextbox loading function, It is a little more limited when trying to do things like this.

    Tough that solution I just gave proably isn't the best. Later on when I'm in front of my other computer with VS.NET installed, I can figure out a much much better way. That or I'm sure osmeone else will give one

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    Thanks, dynamic_sysop! Your code seems to work.

    Thank you everyone for helping me out. I'm greatly appreciate the help.

    ljCharlie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width