How to save a text information with the formatting italic, bold, underline, small, medium, large?
I have a menu, from where I can Save the text as a file, Open a file in my text editor, Exit from my program, but I don't know the coding for Saving and Opening a file, with the format bold, italic, underline, small, medium, large of a text.
Please any suggestions, I need to save the file as fmt extention, i guess i need a separate sequential file, but I just don't know how...
Please help me for this matter.
Thanks in advance.

Dani AI

Generated

As asked: the simplest, most compatible way to keep bold/italic/underline and font sizes is to use a RichText control and save/load RTF (Rich Text Format). RTF preserves all common formatting; you can still give files a custom extension like .fmt, but .rtf is the standard and easiest for compatibility. 's pointer was on the right track — use the control's save/load rather than treating the content as a plain sequential text file.

Example (WinForms VB.NET): use a SaveFileDialog/OpenFileDialog and the RichTextBox SaveFile/LoadFile methods with RichText format.

' Save (menu Save)
Using sfd As New SaveFileDialog()
    sfd.Filter = "Rich Text Format (*.rtf)|*.rtf|Formatted (*.fmt)|*.fmt|All files (*.*)|*.*"
    sfd.DefaultExt = "rtf"
    If sfd.ShowDialog() = DialogResult.OK Then
        RichTextBox1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText)
    End If
End Using
' Open (menu Open)
Using ofd As New OpenFileDialog()
    ofd.Filter = "Rich Text Format (*.rtf)|*.rtf|Formatted (*.fmt)|*.fmt|All files (*.*)|*.*"
    If ofd.ShowDialog() = DialogResult.OK Then
        RichTextBox1.LoadFile(ofd.FileName, RichTextBoxStreamType.RichText)
    End If
End Using

Notes and troubleshooting: saving plain text (sequential File/Open/PrintLine) will lose formatting. You can also read/write the RichTextBox.Rtf string (File.WriteAllText / File.ReadAllText) if you want manual control of the file extension. If you need web-friendly output, convert RTF to HTML or save as HTML instead. Do not load RTF from untrusted sources without validation (RTF can embed objects), and if you want cross-app compatibility prefer the .rtf extension. If using a different framework (WPF, older VB6 controls), the same idea applies: save the control's RTF/XAML/HTML representation rather than plain text.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.