Underline text

I was wondering if there was any way to underline the text of a string...
Application: For right now I am outputing a bunch of strings into a message string to display in a message box. Later I will be outputting to a text file. I have searched the MSDN Lib to no avail; if someone could point me in the right direction, that would be great. Can you use HTML code in VC#
Thanks

Thom


Answer this question

Underline text

  • yoshikatsu

    you can write to an rtf/doc file via a streamwriter HOWEVER, it may not write correctly to comply with the standard formatting/format of a word/RTF file. To do this, a richtextbox control has the LoadFile and Save methods to correctly write to the RTF file in the correct format.

    In order to make a correct/proper rtf file, you need to know about the rtf encoding etc...



  • connect2sandeep

    I guess here is my problem then... I have a form where users enter info for a MLA style format citation. They enter it into text boxes which I format into a string (strCitation) which I then turn into rich text (uiBookRichTextBox.Text = strCitation) which I save to the file. I need to be able to add to the original file so I can do maybe ten or fifteen citations before moving on to use the text elsewhere.

    Any thoughts
    Should I change all the textbox controls to RichTextBox Controls

    Thanks Tom

  • Prabhu000

    I am still a noob with c# and am unsure about creating my own message box :-\. Would it just be creating a newform and just calling an instace of it from my app Also can you use streamwriter to write to an rtf or doc file

    Thanks Thomas

  • Richard Proudfoot

    So a regular string cant be made to be underlined Do I have to wait until i save to a file to have it underlined Can I underline the text in a message box pop up
    Thanks

    Tom

  • Ross Watson

    Here is what I am doing. I am taking input from a user into text boxes to form a MLA style citation. I then take that input and put it into a string which I then assign to the RichTextBox Control to save as a RTF file. When someone is doning a works cited page they may need to do ten or fifteen citations before transfering them to the final paper. Is there any way I can amend the file for something like that


    Any Ideas
    Should I change all the Text box controls to richtextbox controls

    Thanks

    Thomas

  • I.H

    Just one last thing for now: will that operation allow for the fiel to be appended on multilpe runs of the program It sounds like that will just make the stream longer then write to the file, its not appending the file each time it is run it would just overwrite on the next run Is there anything for that

    Thanks
    Tom

  • Murtaza Ali

    Consider using a RichTextBox and saving as an rtf file. It is not possible to make underlined text in a regular plain-text file (.txt).

  • rwbta

    You can't have underlined text in a .txt file, but you can in a .rtf or .htm file. I don't think you can have formatted text in a message box, but you could consider making your own message dialog with something like a RichTextLabel on it.

  • Tom Janssen

    that's correct it will overwrite it by default. Fortunately in one of the overloads for the SaveFile(), you can use a stream to append to the stream. The best way perhaps would be to use a Memorystream to append to the stream then finally when wanting to actually write the file, just read everything from the stream and write it to file.

    When loading, pretty much the same thing except you load the entire file into the memorystream.

    here is an example on how to achieve the appending:

    http://msdn2.microsoft.com/en-us/library/ms160336.aspx

    Hope this gives you some steps!



  • Jim Ward

    Is there any way to append an RTF file
    Currently this is my code :
    richTextBox1.SaveFile(System.Environment.GetFolderPath
    (System.Environment.SpecialFolder.Personal)+ @"\Testdoc.rtf");
    which saves a file called Testdoc.rtf but if you click save once, then change the text and save again it doesn't append it just overwrites it. How can you just append it

    Thanks Thomas

  • ravindra_pn

    it will keep appending to the stream until you finally want to commit changes to the file, then read the entire stream into the file.

    You of course need to read the entire file into the memorystream, when loading, so it can continue on appending to the stream. You need to of course as stated in the doc/shown by example, make the memorystream a global scope so other methods can access it through the class. Make sure you clear out/create a new instance of the memorystream when loading a file to prevent it from appending to the previous file.

    I tried using a FileStream to append to the file but did not work unfortunately. You can do it, by using the memorystream and the example in the doc



  • c_shah

    update: tried using the FileStream again, it appears not to be appending even though set to append but doesn't show it however the file size increases....interesting.

  • quiklearner

    hang on.... I re-read your post

    this is natural. If you save the file, then delete text and add the text again (Different text) then yes it will "overwrite" it, its natural. However if you append to a loaded file in the RTB control and append to it, and save it, it will save the entire thing as is displayed in the RTB control....this is not what you are after

    so if I loaded a file and it had "hi" on it, then I added to it at the end "how are you" and saved it, you should get the file to read "hi how are you"

    if you replaced "hi" with "hey" and saved it, it will say "hey" as that is what was entered....

    whatever is written into the richtextbox control is saved as is to the file



  • varunsagii

    "Would it just be creating a newform and just calling an instace of it from my app "

    Yes, You have to Create a Form to be a message, setting proprties like, ControlBox = false; TopMost=true; StartPostion = CentreParent etc.

    You have to work with Dialog result and assign the values aprpriately on clicking on different buttons.

    "Also can you use streamwriter to write to an rtf or doc file"

    Yes! you can do it.



  • Underline text