Color as Param

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

    Color as Param

    public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string strMensagem,
    Color.???)
    {
    lblMsg.Text = strMensagem;
    lblMsg.ForeColo r = clrLabel.???
    }

    I need to give the color as a param, wich type should i use ?


  • John B

    #2
    Re: Color as Param

    Daniel Groh wrote:[color=blue]
    > public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string strMensagem,
    > Color.???)
    > {
    > lblMsg.Text = strMensagem;
    > lblMsg.ForeColo r = clrLabel.???
    > }
    >
    > I need to give the color as a param, wich type should i use ?
    >
    >[/color]
    system.color ?
    JB

    Comment

    • John B

      #3
      Re: Color as Param

      Daniel Groh wrote:[color=blue]
      > public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string strMensagem,
      > Color.???)
      > {
      > lblMsg.Text = strMensagem;
      > lblMsg.ForeColo r = clrLabel.???
      > }
      >
      > I need to give the color as a param, wich type should i use ?
      >
      >[/color]
      system.color ?
      JB

      Comment

      • Daniel Groh

        #4
        Re: Color as Param

        No...there is System.Drawing. Color but it's not working as a reference!

        if i do

        System.Drawing. Color myColor

        myColor.(point) ...

        it's showing to me properties that dont solve my probleb of textcolor!

        "John B" <jbngspam@yahoo .com> escreveu na mensagem
        news:428d6662$0 $79457$14726298 @news.sunsite.d k...[color=blue]
        > Daniel Groh wrote:[color=green]
        >> public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
        >> strMensagem, Color.???)
        >> {
        >> lblMsg.Text = strMensagem;
        >> lblMsg.ForeColo r = clrLabel.???
        >> }
        >>
        >> I need to give the color as a param, wich type should i use ?
        >>
        >>[/color]
        > system.color ?
        > JB[/color]


        Comment

        • Daniel Groh

          #5
          Re: Color as Param

          No...there is System.Drawing. Color but it's not working as a reference!

          if i do

          System.Drawing. Color myColor

          myColor.(point) ...

          it's showing to me properties that dont solve my probleb of textcolor!

          "John B" <jbngspam@yahoo .com> escreveu na mensagem
          news:428d6662$0 $79457$14726298 @news.sunsite.d k...[color=blue]
          > Daniel Groh wrote:[color=green]
          >> public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
          >> strMensagem, Color.???)
          >> {
          >> lblMsg.Text = strMensagem;
          >> lblMsg.ForeColo r = clrLabel.???
          >> }
          >>
          >> I need to give the color as a param, wich type should i use ?
          >>
          >>[/color]
          > system.color ?
          > JB[/color]


          Comment

          • Maqsood Ahmed

            #6
            Re: Color as Param

            Hello,
            You can use this:

            public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
            strMensagem,Sys tem.Drawing.Col or color);
            {
            lblMsg.Text = strMensagem;
            lblMsg.ForeColo r = color;
            }

            and later use it like this:
            LabelMsg("Hello World","Hi World", Color.Red)

            HTH. Cheers:)
            Maqsood Ahmed [MCP,C#]
            Kolachi Advanced Technologies


            *** Sent via Developersdex http://www.developersdex.com ***

            Comment

            • Maqsood Ahmed

              #7
              Re: Color as Param

              Hello,
              You can use this:

              public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
              strMensagem,Sys tem.Drawing.Col or color);
              {
              lblMsg.Text = strMensagem;
              lblMsg.ForeColo r = color;
              }

              and later use it like this:
              LabelMsg("Hello World","Hi World", Color.Red)

              HTH. Cheers:)
              Maqsood Ahmed [MCP,C#]
              Kolachi Advanced Technologies


              *** Sent via Developersdex http://www.developersdex.com ***

              Comment

              • John B

                #8
                Re: Color as Param

                Daniel Groh wrote:[color=blue]
                > No...there is System.Drawing. Color but it's not working as a reference!
                >
                > if i do
                >
                > System.Drawing. Color myColor
                >
                > myColor.(point) ...
                >
                > it's showing to me properties that dont solve my probleb of textcolor!
                >[/color]
                Doh!
                Knew I should have checked that first :)
                It is still the correct type to use though.
                What is it not doing that you want it to?

                What is MyColor.(point) ?

                Color is static.

                lblMyLabel.Fore Color = System.Drawing. Color.SteelBlue ;

                JB


                [color=blue]
                > "John B" <jbngspam@yahoo .com> escreveu na mensagem
                > news:428d6662$0 $79457$14726298 @news.sunsite.d k...
                >[color=green]
                >>Daniel Groh wrote:
                >>[color=darkred]
                >>>public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
                >>>strMensage m, Color.???)
                >>>{
                >>> lblMsg.Text = strMensagem;
                >>> lblMsg.ForeColo r = clrLabel.???
                >>>}
                >>>
                >>>I need to give the color as a param, wich type should i use ?
                >>>
                >>>[/color]
                >>
                >>system.colo r ?
                >>JB[/color]
                >
                >
                >[/color]

                Comment

                • John B

                  #9
                  Re: Color as Param

                  Daniel Groh wrote:[color=blue]
                  > No...there is System.Drawing. Color but it's not working as a reference!
                  >
                  > if i do
                  >
                  > System.Drawing. Color myColor
                  >
                  > myColor.(point) ...
                  >
                  > it's showing to me properties that dont solve my probleb of textcolor!
                  >[/color]
                  Doh!
                  Knew I should have checked that first :)
                  It is still the correct type to use though.
                  What is it not doing that you want it to?

                  What is MyColor.(point) ?

                  Color is static.

                  lblMyLabel.Fore Color = System.Drawing. Color.SteelBlue ;

                  JB


                  [color=blue]
                  > "John B" <jbngspam@yahoo .com> escreveu na mensagem
                  > news:428d6662$0 $79457$14726298 @news.sunsite.d k...
                  >[color=green]
                  >>Daniel Groh wrote:
                  >>[color=darkred]
                  >>>public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
                  >>>strMensage m, Color.???)
                  >>>{
                  >>> lblMsg.Text = strMensagem;
                  >>> lblMsg.ForeColo r = clrLabel.???
                  >>>}
                  >>>
                  >>>I need to give the color as a param, wich type should i use ?
                  >>>
                  >>>[/color]
                  >>
                  >>system.colo r ?
                  >>JB[/color]
                  >
                  >
                  >[/color]

                  Comment

                  • Paperback Writer

                    #10
                    Re: Color as Param

                    That's tha way...I found it!

                    private void Page_Load(objec t sender, System.EventArg s e)
                    {
                    lblMsg.Text = "Testando parĂ¢metro de cores";
                    SetColor(lblMsg ,"Red");
                    }

                    private void SetColor(Label lblTexto, string strColor)
                    {
                    lblTexto.ForeCo lor = System.Drawing. Color.FromName( strColor); //This
                    method is the way --FromName--
                    }


                    --
                    Please, check my theSpoke:


                    "Maqsood Ahmed" <maqsood_ahmed@ gawab.com> escreveu na mensagem
                    news:eg%23Uj4PX FHA.2468@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                    > Hello,
                    > You can use this:
                    >
                    > public LabelMsg(System .Web.UI.WebCont rols.Label lblMsg, string
                    > strMensagem,Sys tem.Drawing.Col or color);
                    > {
                    > lblMsg.Text = strMensagem;
                    > lblMsg.ForeColo r = color;
                    > }
                    >
                    > and later use it like this:
                    > LabelMsg("Hello World","Hi World", Color.Red)
                    >
                    > HTH. Cheers:)
                    > Maqsood Ahmed [MCP,C#]
                    > Kolachi Advanced Technologies
                    > http://www.kolachi.net
                    >
                    > *** Sent via Developersdex http://www.developersdex.com ***[/color]


                    Comment

                    • John B

                      #11
                      Re: Color as Param

                      Paperback Writer wrote:[color=blue]
                      > That's tha way...I found it!
                      >
                      > private void Page_Load(objec t sender, System.EventArg s e)
                      > {
                      > lblMsg.Text = "Testando parĂ¢metro de cores";
                      > SetColor(lblMsg ,"Red");
                      > }
                      >
                      > private void SetColor(Label lblTexto, string strColor)
                      > {
                      > lblTexto.ForeCo lor = System.Drawing. Color.FromName( strColor); //This
                      > method is the way --FromName--
                      > }
                      >
                      >[/color]
                      UGLYYYYYY :)


                      Seriously, doing this is less intuitive, and way more fragile than
                      passing color as a color type.

                      I (or any future developers) can now break your code by doing
                      SetColor(lblmsg , "BlaBlaBla" )

                      How about

                      private void SetColor(Label label, Color color)
                      {
                      label.ForeColor = color;
                      }


                      ....
                      SetColor(myLabe l, Color.Red);

                      Then, the programmer will get strong typing, (cannot pass an invalid
                      color), intellisense support etc..

                      Color.FromName will also incur a performance hit as well because it will
                      have to parse your string and map it to a valid colour.

                      HTH

                      JB

                      Comment

                      Working...