CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2005
    Posts
    5

    Loading a .rtf into a richtextbox on load

    I was wondering if anyone could tell me how i could load an .rtf file that i have into a richtextbox when the form starts. I know it seems simple but could someone please help me.

  2. #2
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Loading a .rtf into a richtextbox on load

    I suggest always checking the help topic for the members of the class you are using first. Call LoadFile in the form's Load event handler.

  3. #3
    Join Date
    Aug 2005
    Posts
    5

    Re: Loading a .rtf into a richtextbox on load

    Apparently , you did not understand that i was looking for help, not usless information that I have already tried, hence the reason why i've asked. I've spent about a full week looking for information through the web and msdn for the code i'm looking for, do me a favor, if you dont have anything usefull to say, dont say it at all.

  4. #4
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Loading a .rtf into a richtextbox on load

    You are presumably frustrated at having wasted so much time trying to do this but please keep yourself in check. I would assume that anyone coding VB.NET would know how to call a method and use an event handler, as they are fundamental to the language, thus I thought that while my answer may have been terse, it would still be useful. To simply say you did not understand my answer and a request to elaborate would have been sufficient. Let me give you some information that hopefully you will find useful, both in this situation and in avoiding similar situations in the future.

    Every class in the .NET Framework has a help topic dedicated to listing its members. You can get to that help topic a number of ways, but the easiest is to click either the object of interest in the design window or the variable of interest in the code window and press the F1 key. Then you can look down the list of member properties and methods, that are usually named such that their purpose is quite obvious. Doing that would have brought you to the quite obviously named LoadFile method in about 30 seconds, rather than the week you claim to have spent so far. The brief description next to the name says:
    Loads the contents of a file into the RichTextBox control.
    You could then click the name of the method to jump to the help topic dedicated to that method, which would tell you exactly how to use it.

    As for the form's Load event handler, Load is the default event for the Form class, which means you can simply double-click the form in the design window and the IDE will create an empty event handler for you. Alternatively, you could select the object of interest and the event of interest from the drop-down lists at the top of the code window and an empty event handler would be created for you again. Here's an example of what your code should look like:
    Code:
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.RichTextBox1.LoadFile("file name here.")
    End Sub
    You should note that once you type the "." after the variable name, Intellisense provides a member list for you also. You can browse this list looking for members with names that sound appropriate and click one to get a tooltip description also.

    Hopefully this answer has improved your fishing ability, as well as providing you with some fish.

  5. #5
    Join Date
    Jul 2004
    Posts
    142

    Re: Loading a .rtf into a richtextbox on load

    Hello Destination,

    I know you are frustrated and did not find mcilhinney's first answer useful,
    but once, when I answered a question and the guy responded like that,
    I did not give him further help.

    Fortunately for you, mcilhinney was more patient than I.

    I mean, it's not like we get paid or anything.

    Just a suggestion.

  6. #6
    Join Date
    Aug 2005
    Posts
    5

    Re: Loading a .rtf into a richtextbox on load

    I do apoligize for my quick response, I am very frustrated and the answer you supplied in the post was very misunderstood. My quick words were obviously the incorrect reaction and I do thank you for being patient with me.I hope this does not prevent you from posting answers to questions I might have in the future as your post I see are very helpfull. I am not used to VB>NET yet as i have used VB6 and it is similar but very different. Again thank you for the valuable information.

  7. #7
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Loading a .rtf into a richtextbox on load

    ok just to clarify a lil more things because I believe that jmcilhinney answered you on the first post.

    I suggest always checking the help topic for the members of the class you are using first. Call LoadFile in the form's Load event handler
    is the same answer as

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.RichTextBox1.LoadFile("file name here.")
    End Sub
    but it's just in plain english instead of in VB code.

    We don't have to give answer. We're not paid for this and obviously we don't have to be on the receiving end of a rude behavior. Thank god you apologized.
    Nicolas Bohemier

  8. #8
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Loading a .rtf into a richtextbox on load

    Quote Originally Posted by Destination
    I am not used to VB>NET yet as i have used VB6 and it is similar but very different.
    My advice to VB6 users moving to VB.NET is to treat it like a whole new language. Learn VB.NET from scratch and if something turns out to be the same as it was in VB6 then consider that a bonus. Trying to do things the VB6 way will often hinder you in writing good VB.NET code and from learning the language properly. You may have worked out by now that I am a big fan of the help system. I suggest to everyone that they make great use of its search feature and also to wear out their F1 key.

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

Featured