Notepad program wants to write Fonts and Colors in XML.

Hello,

I have a notepad program which saves file in xml format. It saves current color and font along with all features in FontDialog and ColorDialog like underline etc.
Here is the sample of a file i created in the program.

< xml version="1.0" >
<File>
<Format>
<Fontface>Tahoma</Fontface>
<Fontbold>True</Fontbold>
<Fontitalic>False</Fontitalic>
<Fontsize>15.75</Fontsize>
<Fontunderline>True</Fontunderline>
<Fontstrikeout>True</Fontstrikeout>
<Fontcolor>Color [Red]</Fontcolor>
</Format>
<Data>Testing</Data>
</File>

Now as you can the problem is with Color... coz sometimes the ColorDialog gives me Color in RGB format and sometimes like Color[Red] !

Here is what i have used in Streamwriter -

sr.WriteLine(vbTab & vbTab & "<Fontcolor>" & Convert.ToString(TextBox1.ForeColor) & "</Fontcolor>")


Here is what i have used in StreamReader -

Dim forecolor As String = temp.Substring((temp.IndexOf("<Fontcolor>") + 11), (temp.IndexOf("</Fontcolor>") - 11) - (temp.IndexOf("<Fontcolor>")))

Now If we compare this with the above file -

forecolor string shud have this value - Color [Red]

Again i am dazzled as to how i convert a Color in string to a Color

Help me please !


Answer this question

Notepad program wants to write Fonts and Colors in XML.

  • Sudheer George

    No considerations, USE XmlReader and XmlWriter, this is what they are for. Using StreamReader and StreamWriter for this, in my opinion is entirely inappropriate. And I agree that Color.ToArbg and FromArbg is the way that's consisted. I think it might also be better to use Color.ToArbg().ToString("X"). This will write the color values out in Hex which is more traditional.

  • Andre&amp;#39;s

     Convert.ToString

    Don't do this.......... instead

    Save it as a value.....and not a string

     



  • CharlesF

    Try using Color.ToArgb to convert it to an integer for writing and Color.FromArgb to convert it back to a color when reading. .NET has extensive support for reading and writing XML files, consider using the XMLReader class to parse your XML file.

    The next VS version is being worked on using the project name "Orcas". There'll be big changes ahead (WinFX), google the project name.


  • Ken_Bussell

    Thank you very much ! It worked Perfectly ....!



  • aarongreenberg

    Can you tell me what should i use in the Streamwriter and in Streamreader

    Are you talking about RGB values... how can i convert the ForeColor of a textbox to a RBG value and then read it again from a string or an integer to apply it to the opening document

    Can you answer one more query ...

    when is the next visual studio gonna launch
    what is the best way to prepare yourself for future releases

    i am using VS 2005.

    Thanks... I like this place.. i wish i cud talk to microsoft technicians i have something to discuss.


  • MadGerbil

    Next version of Visual Studio Crikey.

    I think what we have is what we've got for a few years - I can't see a lot of improvements needing to it. Ofcourse .NET Framework 3.0 extends version 2.0, but I'm sure that'll really be just addressed with a VS Service pack.

    Oh, And I agree about the XML Thing - Use the XmlReader/Writer - no Excuses



  • Notepad program wants to write Fonts and Colors in XML.