Results 1 to 10 of 10

Thread: loading a rtf file from project?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    loading a rtf file from project?

    is it possible to add a rich-text file to my project and then load it to a rich textbox by code? I'm confused!!!! I added teh file to the project, but I have no idea how to load it


    btw the reason that I wanna do this is because I can't format/colorize the text inside the rich textbox during design time. So I thought I have to make a file with msword and then load it at runtime. is this the right way though?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    VB Code:
    1. private void button3_Click(object sender, System.EventArgs e)
    2. {
    3.     if(openFile.ShowDialog() == DialogResult.OK)
    4.     {
    5.         richTextBox1.LoadFile(openFile.FileName, RichTextBoxStreamType.RichText);
    6.     }
    7. }
    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by DevGrp
    VB Code:
    1. private void button3_Click(object sender, System.EventArgs e)
    2. {
    3.     if(openFile.ShowDialog() == DialogResult.OK)
    4.     {
    5.         richTextBox1.LoadFile(openFile.FileName, RichTextBoxStreamType.RichText);
    6.     }
    7. }
    EEEEEEEEEEEEEEEEEEEEEEEEEH?!!!!!!!

    I dont want the user to load the file. I want the file to be automatically loaded. AND I dont want teh file to be outside the project, I want it to be a part of my project included in the exe file (a resource or whatever?)
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Ok, I'm working on it
    Dont gain the world and lose your soul

  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Ok, I've hit a stump . Loading images is pretty simple, but the *.rtf file is giving problems. I'm off from work tommorow, so I'll see what I can do in the morning.
    Dont gain the world and lose your soul

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    thanks for helping... I just dont know why the heck they didnt provide a way for the user to copy/paste something with rtf format at design time.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  7. #7
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Ok I finally figured out how to do it. Did'nt realize it was so easy. It only took me three lines of code to do it.

    No this is a 2 step process. First you have to create the resource (this is hardest part if you have to write the code yourself), then you have to add that resource to your program. Now since I'm going to be doing this more often, I've created a program to write the resource file for. Right now it only supports text files but I'll add image and icon file support later.

    Now comes the easy part. After you have created your resource file, you just add it to project. Go to the solution explorer and right click -> add existing items, then select the resource file that you created.

    Now loading the resource is very simple
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         'We are loading the resource thats in the executing assembly
    3.         'ResourceExample.Template is the resource file
    4.         'ResourceExample is the executing assembly's namespace, and Template is the first part of the Template.resources
    5.         'So, in any program, it would be <name of the executing assembly's namepace>.<first part of filename.resources>
    6.         Dim rm As New ResourceManager("ResourceExample.Template", [Assembly].GetExecutingAssembly())
    7.  
    8.         'Loading the string resource based on the internal name given to the resource when it was firsted created
    9.         RichTextBox1.Rtf = rm.GetString("Template")
    10.  
    11.         'Release all resources
    12.         rm.ReleaseAllResources()
    13. End Sub
    Hope that helps. I've included the example, plus the Resource Writer.
    Attached Files Attached Files
    Dont gain the world and lose your soul

  8. #8

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Work perfect !!! thanks!!! : )

    Umm btw how do you make a resouce with code?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  9. #9
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i just think u cant because that would involve changing the exe at runtime
    \m/\m/

  10. #10
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Thats right PT. Its a two step process. Seems kind of strange though that MS would do something like this. Thats why I made a separate program just to make the resource files.

    Here is the code to generate a resource file with strings
    Code:
    ResourceWriter rw = new ResourceWriter("Test.resources");
    rw.AddResource("1","This is a Test 1");
    rw.AddResource("2","This is a Test 2");
    rw.AddResource("3","This is a Test 3");
    rw.Generate();
    rw.Close();
    Dont gain the world and lose your soul

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