Convert String to COlor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jcrouse

    #16
    Re: Convert String to COlor

    Well...this seems to work:

    lblP1JoyUp.Fore Color =
    Color.FromArgb( ds.Tables(0).Ro ws(0).Item(5))

    lblP1JoyUp.Back Color =
    Color.FromArgb( ds.Tables(0).Ro ws(0).Item(6))


    Does it look correct?

    Thanks,
    John



    "jcrouse" <me> wrote in message news:Ofa2axKUEH A.712@TK2MSFTNG P11.phx.gbl...[color=blue]
    > 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>Micro soft Sans Serif</FontName>
    >
    > <FontSize>8.2 5</FontSize>
    >
    > <FontBold>False </FontBold>
    >
    > <FontItalic>Fal se</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(Open FileDialog1.Fil eName)
    >
    > lblP1JoyUp.Top = ds.Tables(0).Ro ws(0).Item(0).T oString
    >
    > lblP1JoyUp.Left = ds.Tables(0).Ro ws(0).Item(1).T oString
    >
    > lblP1JoyUp.Heig ht = ds.Tables(0).Ro ws(0).Item(2).T oString
    >
    > lblP1JoyUp.Widt h = ds.Tables(0).Ro ws(0).Item(3).T oString
    >
    > lblP1JoyUp.Visi ble = ds.Tables(0).Ro ws(0).Item(4).T oString
    >
    > lblP1JoyUp.Fore Color.FromArgb( ds.Tables(0).Ro ws(0).Item(5))
    >
    > lblP1JoyUp.Back Color.FromArgb( ds.Tables(0).Ro ws(0).Item(6))
    >
    >
    >
    > Any idea on the reading part,
    >
    > John
    >
    >
    >
    >
    > "J M" <a@b.com> wrote in message
    > news:%23eL%23LZ FUEHA.4048@TK2M SFTNGP12.phx.gb l...[color=green]
    > > 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" <john.crouse@co mcast.net> schreef in bericht
    > > news:uTtokEDUEH A.2408@tk2msftn gp13.phx.gbl...[color=darkred]
    > > > I decided to start a new thread. I have output in xml file format. It[/color]
    > > looks[color=darkred]
    > > > like this:
    > > >
    > > > <P1JoyUp>
    > > > <Top>326</Top>
    > > > <Left>54</Left>
    > > > <Height>23</Height>
    > > > <Width>100</Width>
    > > > <Visible>True </Visible>
    > > > <ForeColor>Colo r [White]</ForeColor>
    > > > <BackColor>Colo r [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[/color][/color][/color]
    I[color=blue][color=green]
    > > need[color=darkred]
    > > > to convert the forecolor and backcolor strings to[/color]
    > > system.drawing. something.[color=darkred]
    > > > WHere do I need to look for an answer.
    > > >
    > > > Thanks,
    > > > John
    > > >
    > > >[/color]
    > >
    > >[/color]
    >
    >[/color]


    Comment

    • Cor Ligthert

      #17
      Re: Convert String to COlor

      Hi John,

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

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

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

      :-)

      I hope this helps

      Cor


      Comment

      • Armin Zingler

        #18
        Re: Convert String to COlor

        "jcrouse" <me> schrieb[color=blue]
        > 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(Open FileDialog1.Fil eName)
        >
        > lblP1JoyUp.Top = ds.Tables(0).Ro ws(0).Item(0).T oString
        >
        > lblP1JoyUp.Left =
        > ds.Tables(0).Ro ws(0).Item(1).T oString
        >
        > lblP1JoyUp.Heig ht =
        > ds.Tables(0).Ro ws(0).Item(2).T oString
        >
        > lblP1JoyUp.Widt h =
        > ds.Tables(0).Ro ws(0).Item(3).T oString
        >
        > lblP1JoyUp.Visi ble =
        > ds.Tables(0).Ro ws(0).Item(4).T oString
        >
        > lblP1JoyUp.Font .Name =
        > ds.Tables(0).Ro ws(0).Item(7).T oString
        >
        > lblP1JoyUp.Font .Size =
        > ds.Tables(0).Ro ws(0).Item(8).T oString
        >
        > lblP1JoyUp.Font .Bold =
        > ds.Tables(0).Ro ws(0).Item(9).T oString
        >
        > lblP1JoyUp.Font .Italic =
        > ds.Tables(0).Ro ws(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?[/color]


        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).tostri ng, <other properties
        here>)


        --
        Armin

        How to quote and why:



        Comment

        • Jay B. Harlow [MVP - Outlook]

          #19
          Re: Convert String to COlor

          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:ub64ktKUEH A.2564@TK2MSFTN GP11.phx.gbl...[color=blue]
          > Well, this seems nice and simple. However, if you look at the xml file,[/color]
          the[color=blue]
          > 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[/color]
          actual[color=blue]
          > 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:ODCY1xEUEH A.4048@TK2MSFTN GP12.phx.gbl...[color=green]
          > > Color.FromName( "White")
          > >
          > > OHM
          > >
          > > "jcrouse" <john.crouse@co mcast.net> wrote in message
          > > news:uTtokEDUEH A.2408@tk2msftn gp13.phx.gbl...[color=darkred]
          > > > I decided to start a new thread. I have output in xml file format. It[/color]
          > > looks[color=darkred]
          > > > like this:
          > > >
          > > > <P1JoyUp>
          > > > <Top>326</Top>
          > > > <Left>54</Left>
          > > > <Height>23</Height>
          > > > <Width>100</Width>
          > > > <Visible>True </Visible>
          > > > <ForeColor>Colo r [White]</ForeColor>
          > > > <BackColor>Colo r [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[/color][/color][/color]
          I[color=blue][color=green]
          > > need[color=darkred]
          > > > to convert the forecolor and backcolor strings to[/color]
          > > system.drawing. something.[color=darkred]
          > > > WHere do I need to look for an answer.
          > > >
          > > > Thanks,
          > > > John
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #20
            Re: Convert String to COlor

            John,[color=blue]
            > But now when I try to handle the font components individually it[/color]
            underlines[color=blue]
            > the four font line and says "font.xxxx property is read only. Here is the
            > code for reading the xml file back in:[/color]
            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:eeBgPgKUEH A.4064@TK2MSFTN GP11.phx.gbl...[color=blue]
            > 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("P1Jo yUp").NewRow
            >
            > dr1("Top") = lblP1JoyUp.Top. ToString
            >
            > dr1("Left") = lblP1JoyUp.Left .ToString
            >
            > dr1("Height") = lblP1JoyUp.Heig ht.ToString
            >
            > dr1("Width") = lblP1JoyUp.Widt h.ToString
            >
            > dr1("Visible") = lblP1JoyUp.Visi ble.ToString
            >
            > dr1("FontName") = lblP1JoyUp.Font .Name.ToString
            >
            > dr1("FontSize") = lblP1JoyUp.Font .Size.ToString
            >
            > dr1("FontBold") = lblP1JoyUp.Font .Bold.ToString
            >
            > dr1("FontItalic ") = lblP1JoyUp.Font .Italic.ToStrin g
            >
            > Here is what the xml file looks like:
            >
            > <CPViewer>
            >
            > <P1JoyUp>
            >
            > <Top>10</Top>
            >
            > <Left>10</Left>
            >
            > <Height>23</Height>
            >
            > <Width>100</Width>
            >
            > <Visible>Fals e</Visible>
            >
            > <ForeColor>Colo r [White]</ForeColor>
            >
            > <BackColor>Colo r [Transparent]</BackColor>
            >
            > <FontName>Micro soft Sans Serif</FontName>
            >
            > <FontSize>8.2 5</FontSize>
            >
            > <FontBold>False </FontBold>
            >
            > <FontItalic>Fal se</FontItalic>
            >
            > </P1JoyUp>
            >
            >
            > But now when I try to handle the font components individually it[/color]
            underlines[color=blue]
            > 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(Open FileDialog1.Fil eName)
            >
            > lblP1JoyUp.Top = ds.Tables(0).Ro ws(0).Item(0).T oString
            >
            > lblP1JoyUp.Left = ds.Tables(0).Ro ws(0).Item(1).T oString
            >
            > lblP1JoyUp.Heig ht = ds.Tables(0).Ro ws(0).Item(2).T oString
            >
            > lblP1JoyUp.Widt h = ds.Tables(0).Ro ws(0).Item(3).T oString
            >
            > lblP1JoyUp.Visi ble = ds.Tables(0).Ro ws(0).Item(4).T oString
            >
            > lblP1JoyUp.Font .Name = ds.Tables(0).Ro ws(0).Item(7).T oString
            >
            > lblP1JoyUp.Font .Size = ds.Tables(0).Ro ws(0).Item(8).T oString
            >
            > lblP1JoyUp.Font .Bold = ds.Tables(0).Ro ws(0).Item(9).T oString
            >
            > lblP1JoyUp.Font .Italic =[/color]
            ds.Tables(0).Ro ws(0).Item(10). ToString[color=blue]
            >
            > lblP1JoyUp.Text = lblP1JoyUp.Name
            >
            >
            > Like I said, this worked a few days ago but I can't figure it out now. Do[/color]
            I[color=blue]
            > need to ".ToString" when I am reading back in?
            >
            > Thanks,
            > John
            >
            >
            >
            > "Cor Ligthert" <notfirstname@p lanet.nl> wrote in message
            > news:ejKlEsEUEH A.704@TK2MSFTNG P09.phx.gbl...[color=green]
            > > Hi John,
            > >
            > > It is possible with that string to extract it using a regex, a split or[/color][/color]
            an[color=blue][color=green]
            > > indexof or any combination of that.
            > >
            > > However much easier is just to save the components of the font seperatly[/color]
            > in[color=green]
            > > your XML file
            > > (I showed you it the way you did to make it not that difficult[/color][/color]
            explaining[color=blue]
            > it[color=green]
            > > in a message, although I told that somewhere in a thread of you in this
            > > newsgroup)
            > >
            > > blablaFontName = textbox1.font.n ame.tostring
            > > blablaFondSize = textbox1.font.s ize.tostring
            > > etc.
            > >
            > > Than setting it back is much easier
            > > textbox1.font = new font(blablaFont Name, csng(blablaFont Size))
            > >
            > > I hope this helps?
            > >
            > > Cor
            > >
            > >[/color]
            >
            >[/color]


            Comment

            Working...