473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Convert String to COlor

I decided to start a new thread. I have output in xml file format. It looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need
to convert the forecolor and backcolor strings to system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John
Nov 20 '05 #1
19 5131
Have you tried converting to a color in the color class?

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It looks like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need to convert the forecolor and backcolor strings to system.drawing.something. WHere do I need to look for an answer.

Thanks,
John

Nov 20 '05 #2
I'm looking at the Color class and typeconverters but I dont' understand the
typedescriptor parameter or the example they give in the msdn help.

John

"Scott M." <s-***@nospam.nospam> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
Have you tried converting to a color in the color class?

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I

need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John


Nov 20 '05 #3
How about CType(colorString,color) ... haven't tried this though.
"jcrouse" <me> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm looking at the Color class and typeconverters but I dont' understand the typedescriptor parameter or the example they give in the msdn help.

John

"Scott M." <s-***@nospam.nospam> wrote in message
news:uW**************@TK2MSFTNGP09.phx.gbl...
Have you tried converting to a color in the color class?

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in
I need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John



Nov 20 '05 #4
Hi John,

It is possible with that string to extract it using a regex, a split or an
indexof or any combination of that.

However much easier is just to save the components of the font seperatly in
your XML file
(I showed you it the way you did to make it not that difficult explaining it
in a message, although I told that somewhere in a thread of you in this
newsgroup)

blablaFontName = textbox1.font.name.tostring
blablaFondSize = textbox1.font.size.tostring
etc.

Than setting it back is much easier
textbox1.font = new font(blablaFontName, csng(blablaFontSize))

I hope this helps?

Cor
Nov 20 '05 #5
Color.FromName("White")

OHM

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It looks like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need to convert the forecolor and backcolor strings to system.drawing.something. WHere do I need to look for an answer.

Thanks,
John

Nov 20 '05 #6
Hi OHM,

I saw I did give the wrong answer on the right question.

(My message was an answer on another question from John in another thread)

(Ken did give this answer as well, so I thought it was another question)

However, thanks for correcting me.

Cor
Nov 20 '05 #7
J M
I always use Color.ToARGB to write, and
Color.FromARGB to read them back again.
I think that's much easier to do...

Hope I helped,
J Mous

"jcrouse" <jo*********@comcast.net> schreef in bericht
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It looks like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need to convert the forecolor and backcolor strings to system.drawing.something. WHere do I need to look for an answer.

Thanks,
John

Nov 20 '05 #8
* "jcrouse" <jo*********@comcast.net> scripsit:
I decided to start a new thread. I have output in xml file format. It looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need
to convert the forecolor and backcolor strings to system.drawing.something.
WHere do I need to look for an answer.


\\\
Me.BackColor = Color.FromName("Rosybrown")
///

- or -

\\\
Dim ColorName As String = ...
Me.Label1.BackColor = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), ColorName), KnownColor))
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
Another problem. I had this working about two days ago. What am I missing
here. Here is how I write out to the xml file:

Dim dr1 As DataRow = ds.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dr1("Left") = lblP1JoyUp.Left.ToString

dr1("Height") = lblP1JoyUp.Height.ToString

dr1("Width") = lblP1JoyUp.Width.ToString

dr1("Visible") = lblP1JoyUp.Visible.ToString

dr1("FontName") = lblP1JoyUp.Font.Name.ToString

dr1("FontSize") = lblP1JoyUp.Font.Size.ToString

dr1("FontBold") = lblP1JoyUp.Font.Bold.ToString

dr1("FontItalic") = lblP1JoyUp.Font.Italic.ToString

Here is what the xml file looks like:

<CPViewer>

<P1JoyUp>

<Top>10</Top>

<Left>10</Left>

<Height>23</Height>

<Width>100</Width>

<Visible>False</Visible>

<ForeColor>Color [White]</ForeColor>

<BackColor>Color [Transparent]</BackColor>

<FontName>Microsoft Sans Serif</FontName>

<FontSize>8.25</FontSize>

<FontBold>False</FontBold>

<FontItalic>False</FontItalic>

</P1JoyUp>
But now when I try to handle the font components individually it underlines
the four font line and says "font.xxxx property is read only. Here is the
code for reading the xml file back in:

If OpenFileDialog1.FileName <> "" Then

Dim ds As New DataSet

ds.ReadXml(OpenFileDialog1.FileName)

lblP1JoyUp.Top = ds.Tables(0).Rows(0).Item(0).ToString

lblP1JoyUp.Left = ds.Tables(0).Rows(0).Item(1).ToString

lblP1JoyUp.Height = ds.Tables(0).Rows(0).Item(2).ToString

lblP1JoyUp.Width = ds.Tables(0).Rows(0).Item(3).ToString

lblP1JoyUp.Visible = ds.Tables(0).Rows(0).Item(4).ToString

lblP1JoyUp.Font.Name = ds.Tables(0).Rows(0).Item(7).ToString

lblP1JoyUp.Font.Size = ds.Tables(0).Rows(0).Item(8).ToString

lblP1JoyUp.Font.Bold = ds.Tables(0).Rows(0).Item(9).ToString

lblP1JoyUp.Font.Italic = ds.Tables(0).Rows(0).Item(10).ToString

lblP1JoyUp.Text = lblP1JoyUp.Name
Like I said, this worked a few days ago but I can't figure it out now. Do I
need to ".ToString" when I am reading back in?

Thanks,
John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ej*************@TK2MSFTNGP09.phx.gbl...
Hi John,

It is possible with that string to extract it using a regex, a split or an
indexof or any combination of that.

However much easier is just to save the components of the font seperatly in your XML file
(I showed you it the way you did to make it not that difficult explaining it in a message, although I told that somewhere in a thread of you in this
newsgroup)

blablaFontName = textbox1.font.name.tostring
blablaFondSize = textbox1.font.size.tostring
etc.

Than setting it back is much easier
textbox1.font = new font(blablaFontName, csng(blablaFontSize))

I hope this helps?

Cor

Nov 20 '05 #10
Well, this seems nice and simple. However, if you look at the xml file, the
color is specified as "Color [White]" and I only need the part between the
braces. If I modify the xml by hand and strip out everything but the actual
color name, this works great. So, in order to use this method, how do I
write JUST the color as a strin to the xml file.

Thanks,
John
"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
Color.FromName("White")

OHM

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I

need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John


Nov 20 '05 #11
I also like this method. It is easy to write to the xml file with this
method. Here is a sample:

<CPViewer>

<P1JoyUp>

<Top>136</Top>

<Left>99</Left>

<Height>23</Height>

<Width>100</Width>

<Visible>True</Visible>

<ForeColor>-256</ForeColor>

<BackColor>-16777216</BackColor>

<FontName>Microsoft Sans Serif</FontName>

<FontSize>8.25</FontSize>

<FontBold>False</FontBold>

<FontItalic>False</FontItalic>

</P1JoyUp>
However, I can't get the code right to read it back in. This is what I
tried, amoungst many other syntaxes:

If OpenFileDialog1.FileName <> "" Then

Dim ds As New DataSet

ds.ReadXml(OpenFileDialog1.FileName)

lblP1JoyUp.Top = ds.Tables(0).Rows(0).Item(0).ToString

lblP1JoyUp.Left = ds.Tables(0).Rows(0).Item(1).ToString

lblP1JoyUp.Height = ds.Tables(0).Rows(0).Item(2).ToString

lblP1JoyUp.Width = ds.Tables(0).Rows(0).Item(3).ToString

lblP1JoyUp.Visible = ds.Tables(0).Rows(0).Item(4).ToString

lblP1JoyUp.ForeColor.FromArgb(ds.Tables(0).Rows(0) .Item(5))

lblP1JoyUp.BackColor.FromArgb(ds.Tables(0).Rows(0) .Item(6))

Any idea on the reading part,

John


"J M" <a@b.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I always use Color.ToARGB to write, and
Color.FromARGB to read them back again.
I think that's much easier to do...

Hope I helped,
J Mous

"jcrouse" <jo*********@comcast.net> schreef in bericht
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I

need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John


Nov 20 '05 #12
Ken......I tried your method also and failed. Read the reply above to OHM
for my attempt and results at your first recommendation. As for your second
recommendation, I don't understand the "..." at the end of the first line.

Please elaborate more,

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
* "jcrouse" <jo*********@comcast.net> scripsit:
I decided to start a new thread. I have output in xml file format. It looks like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in I need to convert the forecolor and backcolor strings to system.drawing.something. WHere do I need to look for an answer.
\\\
Me.BackColor = Color.FromName("Rosybrown")
///

- or -

\\\
Dim ColorName As String = ...
Me.Label1.BackColor =

Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor),
ColorName), KnownColor)) ///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #13
* "jcrouse" <me> scripsit:
Ken......I tried your method also and failed. Read the reply above to OHM
for my attempt and results at your first recommendation. As for your second
recommendation, I don't understand the "..." at the end of the first line.


Just replace it with a string that contains the name of the color, for
example, "Red".

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #14
Hi,

Dim strColor As String = "Color [White]"
Dim l As Integer = strColor.IndexOf("[")
Dim r As Integer = strColor.IndexOf("]")
Dim strFormatedColor As String = strColor.Substring(l + 1, r - l
- 1)
Dim clrBack As Color = Color.FromName(strFormatedColor)

Me.BackColor = clrBack

Ken
--------------------

"jcrouse" <me> wrote in message
news:eb*************@tk2msftngp13.phx.gbl:
Ken......I tried your method also and failed. Read the reply above to OHM

for my attempt and results at your first recommendation. As for your
second
recommendation, I don't understand the "..." at the end of the first
line.

Please elaborate more,

John

"Herfried K. Wagner [MVP]" <HYPERLINK
"mailto:hi***************@gmx.at"hi*************** @gmx.at> wrote in message

news:uN**************@TK2MSFTNGP11.phx.gbl...
* "jcrouse" <HYPERLINK
"mailto:jo*********@comcast.net"jo*********@comcas t.net> scripsit:

I decided to start a new thread. I have output in xml file format.
It
looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in
I
need
to convert the forecolor and backcolor strings to
system.drawing.something.
WHere do I need to look for an answer.

\\\
Me.BackColor = Color.FromName("Rosybrown")
///

- or -

\\\
Dim ColorName As String = ...
Me.Label1.BackColor =


Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor),
ColorName), KnownColor))
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.1.2 - Release Date: 6/7/2004
Nov 20 '05 #15
Well...this seems to work:

lblP1JoyUp.ForeColor =
Color.FromArgb(ds.Tables(0).Rows(0).Item(5))

lblP1JoyUp.BackColor =
Color.FromArgb(ds.Tables(0).Rows(0).Item(6))
Does it look correct?

Thanks,
John

"jcrouse" <me> wrote in message news:Of*************@TK2MSFTNGP11.phx.gbl...
I also like this method. It is easy to write to the xml file with this
method. Here is a sample:

<CPViewer>

<P1JoyUp>

<Top>136</Top>

<Left>99</Left>

<Height>23</Height>

<Width>100</Width>

<Visible>True</Visible>

<ForeColor>-256</ForeColor>

<BackColor>-16777216</BackColor>

<FontName>Microsoft Sans Serif</FontName>

<FontSize>8.25</FontSize>

<FontBold>False</FontBold>

<FontItalic>False</FontItalic>

</P1JoyUp>
However, I can't get the code right to read it back in. This is what I
tried, amoungst many other syntaxes:

If OpenFileDialog1.FileName <> "" Then

Dim ds As New DataSet

ds.ReadXml(OpenFileDialog1.FileName)

lblP1JoyUp.Top = ds.Tables(0).Rows(0).Item(0).ToString

lblP1JoyUp.Left = ds.Tables(0).Rows(0).Item(1).ToString

lblP1JoyUp.Height = ds.Tables(0).Rows(0).Item(2).ToString

lblP1JoyUp.Width = ds.Tables(0).Rows(0).Item(3).ToString

lblP1JoyUp.Visible = ds.Tables(0).Rows(0).Item(4).ToString

lblP1JoyUp.ForeColor.FromArgb(ds.Tables(0).Rows(0) .Item(5))

lblP1JoyUp.BackColor.FromArgb(ds.Tables(0).Rows(0) .Item(6))

Any idea on the reading part,

John


"J M" <a@b.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
I always use Color.ToARGB to write, and
Color.FromARGB to read them back again.
I think that's much easier to do...

Hope I helped,
J Mous

"jcrouse" <jo*********@comcast.net> schreef in bericht
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in
I need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John



Nov 20 '05 #16
Hi John,

That was the answer above
Extra
Dim myfontstyle As FontStyle
If CBool(ds.Tables(0).Rows(0).Item(9)) = True Then
myfontstyle = FontStyle.Bold
End If
If CBool(ds.Tables(0).Rows(0).Item(10)) = True Then
myfontstyle = myfontstyle Or FontStyle.Italic
End If

lblP1JoyUp.Font = new font(ds.Tables(0).Rows(0).Item(7).ToString,
csng(ds.Tables(0).Rows(0).Item(8)),myfontstyle)

Maybe you should first make some extra fields. And watch typos

:-)

I hope this helps

Cor
Nov 20 '05 #17
"jcrouse" <me> schrieb
But now when I try to handle the font components individually it
underlines the four font line and says "font.xxxx property is read
only. Here is the code for reading the xml file back in:

If OpenFileDialog1.FileName <> "" Then

Dim ds As New DataSet

ds.ReadXml(OpenFileDialog1.FileName)

lblP1JoyUp.Top = ds.Tables(0).Rows(0).Item(0).ToString

lblP1JoyUp.Left =
ds.Tables(0).Rows(0).Item(1).ToString

lblP1JoyUp.Height =
ds.Tables(0).Rows(0).Item(2).ToString

lblP1JoyUp.Width =
ds.Tables(0).Rows(0).Item(3).ToString

lblP1JoyUp.Visible =
ds.Tables(0).Rows(0).Item(4).ToString

lblP1JoyUp.Font.Name =
ds.Tables(0).Rows(0).Item(7).ToString

lblP1JoyUp.Font.Size =
ds.Tables(0).Rows(0).Item(8).ToString

lblP1JoyUp.Font.Bold =
ds.Tables(0).Rows(0).Item(9).ToString

lblP1JoyUp.Font.Italic =
ds.Tables(0).Rows(0).Item(10).ToString

lblP1JoyUp.Text = lblP1JoyUp.Name
Like I said, this worked a few days ago but I can't figure it out
now. Do I need to ".ToString" when I am reading back in?

You can not change Font properties. Don't assign each property, but create a
new Font and pass the font properties to the constructor:

lblp1joyup.font = new font(ds.tables(0)(0)(7).tostring, <other properties
here>)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #18
John,
As I and other have commented before. If you want to read using
Color.FromName, then you need to write Color.Name. Unfortunately
Color.ToString simply will not do it for you!

Hope this helps
Jay

"jcrouse" <me> wrote in message
news:ub**************@TK2MSFTNGP11.phx.gbl...
Well, this seems nice and simple. However, if you look at the xml file, the color is specified as "Color [White]" and I only need the part between the
braces. If I modify the xml by hand and strip out everything but the actual color name, this works great. So, in order to use this method, how do I
write JUST the color as a strin to the xml file.

Thanks,
John
"One Handed Man ( OHM#)" <news.microsoft.com> wrote in message
news:OD**************@TK2MSFTNGP12.phx.gbl...
Color.FromName("White")

OHM

"jcrouse" <jo*********@comcast.net> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
I decided to start a new thread. I have output in xml file format. It

looks
like this:

<P1JoyUp>
<Top>326</Top>
<Left>54</Left>
<Height>23</Height>
<Width>100</Width>
<Visible>True</Visible>
<ForeColor>Color [White]</ForeColor>
<BackColor>Color [Transparent]</BackColor>
<Font>[Font: Name=Microsoft Sans Serif, Size=8.25, Units=3,
GdiCharSet=0, GdiVerticalFont=False]</Font>
</P1JoyUp>

I write it out and read it in using a data set. Now when I read it in
I need
to convert the forecolor and backcolor strings to

system.drawing.something.
WHere do I need to look for an answer.

Thanks,
John



Nov 20 '05 #19
John,
But now when I try to handle the font components individually it underlines the four font line and says "font.xxxx property is read only. Here is the
code for reading the xml file back in: You need to use New Font(x, y, z) where x, y, and z are the font properties
that you wrote to the file.

I mentioned this last week when you asked.

Hope this helps
Jay
"jcrouse" <me> wrote in message
news:ee**************@TK2MSFTNGP11.phx.gbl... Another problem. I had this working about two days ago. What am I missing
here. Here is how I write out to the xml file:

Dim dr1 As DataRow = ds.Tables("P1JoyUp").NewRow

dr1("Top") = lblP1JoyUp.Top.ToString

dr1("Left") = lblP1JoyUp.Left.ToString

dr1("Height") = lblP1JoyUp.Height.ToString

dr1("Width") = lblP1JoyUp.Width.ToString

dr1("Visible") = lblP1JoyUp.Visible.ToString

dr1("FontName") = lblP1JoyUp.Font.Name.ToString

dr1("FontSize") = lblP1JoyUp.Font.Size.ToString

dr1("FontBold") = lblP1JoyUp.Font.Bold.ToString

dr1("FontItalic") = lblP1JoyUp.Font.Italic.ToString

Here is what the xml file looks like:

<CPViewer>

<P1JoyUp>

<Top>10</Top>

<Left>10</Left>

<Height>23</Height>

<Width>100</Width>

<Visible>False</Visible>

<ForeColor>Color [White]</ForeColor>

<BackColor>Color [Transparent]</BackColor>

<FontName>Microsoft Sans Serif</FontName>

<FontSize>8.25</FontSize>

<FontBold>False</FontBold>

<FontItalic>False</FontItalic>

</P1JoyUp>
But now when I try to handle the font components individually it underlines the four font line and says "font.xxxx property is read only. Here is the
code for reading the xml file back in:

If OpenFileDialog1.FileName <> "" Then

Dim ds As New DataSet

ds.ReadXml(OpenFileDialog1.FileName)

lblP1JoyUp.Top = ds.Tables(0).Rows(0).Item(0).ToString

lblP1JoyUp.Left = ds.Tables(0).Rows(0).Item(1).ToString

lblP1JoyUp.Height = ds.Tables(0).Rows(0).Item(2).ToString

lblP1JoyUp.Width = ds.Tables(0).Rows(0).Item(3).ToString

lblP1JoyUp.Visible = ds.Tables(0).Rows(0).Item(4).ToString

lblP1JoyUp.Font.Name = ds.Tables(0).Rows(0).Item(7).ToString

lblP1JoyUp.Font.Size = ds.Tables(0).Rows(0).Item(8).ToString

lblP1JoyUp.Font.Bold = ds.Tables(0).Rows(0).Item(9).ToString

lblP1JoyUp.Font.Italic = ds.Tables(0).Rows(0).Item(10).ToString
lblP1JoyUp.Text = lblP1JoyUp.Name
Like I said, this worked a few days ago but I can't figure it out now. Do I need to ".ToString" when I am reading back in?

Thanks,
John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:ej*************@TK2MSFTNGP09.phx.gbl...
Hi John,

It is possible with that string to extract it using a regex, a split or an indexof or any combination of that.

However much easier is just to save the components of the font seperatly in
your XML file
(I showed you it the way you did to make it not that difficult

explaining it
in a message, although I told that somewhere in a thread of you in this
newsgroup)

blablaFontName = textbox1.font.name.tostring
blablaFondSize = textbox1.font.size.tostring
etc.

Than setting it back is much easier
textbox1.font = new font(blablaFontName, csng(blablaFontSize))

I hope this helps?

Cor


Nov 20 '05 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
2
by: William Stacey | last post by:
Example line: string temp = Convert.ToString(null); Convert.ToString() says it will return empty string if null is passed as parm. This returns a null. Is this oversight in the Convert method?...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
3
by: aaa | last post by:
I have a third party DLL that downloads everything from a device to a particular device into the following Hex format: 080 : 13 70 05 00 (Timestamp) 081 : 35 E1 91 F9 9F BF (Mode 1 Supported...
5
by: simon | last post by:
I have datetime variable: Datetime tsEndTime; Should I use (DateTime): tsEndTime=(DateTime)rdr.GetValue(15) or is better to use: tsEndTime=Convert.ToDateTime(rdr.GetValue(15))
25
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
4
by: simonZ | last post by:
Why this don't work: Boolean test; String testValue; testValue="0"; test=System.Convert.ToBoolean(testValue); How can I convert string to boolean?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.