How to use QBColor in VB.NET?

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

    How to use QBColor in VB.NET?

    Hi,

    In VB6, on every click on Command1, to change the Form background
    color dynamically, I use:

    Private Sub Command1_Click( )
    Me.BackColor = QBColor(Rnd * 14)
    End Sub



    How can I achieve the same in .NET? When I am using QBColor()
    function in .NET, it is giving the the following error:

    Value of type 'Integer' cannot be converted to 'System.Drawing .Color'.


    Regards,
    Kamlesh
  • Tom Spink

    #2
    Re: How to use QBColor in VB.NET?

    Hi, (untested) try:

    Me.BackColor = Color.FromARGB( QBColor(Rnd * 14))

    --
    HTH,
    -- Tom Spink, Über Geek

    Woe be the day VBC.EXE says, "OrElse what?"

    Please respond to the newsgroup,
    so all can benefit
    "Kamlesh" <kamlesh2000@ya hoo.com> wrote in message
    news:2644c0f6.0 402252303.2779b 6ef@posting.goo gle.com...[color=blue]
    > Hi,
    >
    > In VB6, on every click on Command1, to change the Form background
    > color dynamically, I use:
    >
    > Private Sub Command1_Click( )
    > Me.BackColor = QBColor(Rnd * 14)
    > End Sub
    >
    >
    >
    > How can I achieve the same in .NET? When I am using QBColor()
    > function in .NET, it is giving the the following error:
    >
    > Value of type 'Integer' cannot be converted to 'System.Drawing .Color'.
    >
    >
    > Regards,
    > Kamlesh[/color]


    Comment

    • Cor

      #3
      Re: How to use QBColor in VB.NET?

      Hi Kamlesh,

      Have a look at the toargb method



      I hope this helps,

      Cor


      Comment

      • Kamlesh Rao

        #4
        Re: How to use QBColor in VB.NET?

        Hi,

        Tom:
        Color.FromARGB doesn't work. It gives run-time exception.

        Cor:
        My development environment is not showing the ToARGB method? Whats the
        problem? The link sent by you says:

        Syntax based on .NET Framework version 1.1.
        Documentation version 1.1.1.

        Does this mean that I need ver 1.1? How do know my .NET Framework
        version?

        Regards,
        Kamlesh


        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Cor

          #5
          Re: How to use QBColor in VB.NET?

          Hi Kamlesh,

          A combination by me from Toms work and MSDN

          I did not really check what it does :-))

          I hope this works as expected?

          Cor

          \\\
          Dim someColor As Color = _
          Color.FromArgb( QBColor(CInt(Rn d() * 14)))
          Dim colorMatches(16 7) As KnownColor
          Dim count As Integer = 0
          Dim enumValue As KnownColor
          For enumValue = 0 To KnownColor.Yell owGreen
          someColor = Color.FromKnown Color(enumValue )
          If someColor.G <> 0 And someColor.R = 0 And _
          Not someColor.IsSys temColor Then
          colorMatches(co unt) = enumValue
          count += 1
          End If
          Next
          Me.BackColor = someColor
          ///




          Comment

          • Ken Tucker [MVP]

            #6
            Re: How to use QBColor in VB.NET?

            Hi,


            These work. The exception you get is this control doesnt support
            transparent colors. The QBColor doesn't come up with the right color code.

            Dim c As Color = Color.FromArgb(-16776961)

            Dim x As Integer = c.ToArgb()

            Me.BackColor = c

            Ken

            ----------------------

            "Kamlesh Rao" <kamlesh2000@ya hoo.com> wrote in message
            news:uiTqjDF$DH A.712@tk2msftng p13.phx.gbl...[color=blue]
            > Hi,
            >
            > Tom:
            > Color.FromARGB doesn't work. It gives run-time exception.
            >
            > Cor:
            > My development environment is not showing the ToARGB method? Whats the
            > problem? The link sent by you says:
            >
            > Syntax based on .NET Framework version 1.1.
            > Documentation version 1.1.1.
            >
            > Does this mean that I need ver 1.1? How do know my .NET Framework
            > version?
            >
            > Regards,
            > Kamlesh
            >
            >
            > *** Sent via Developersdex http://www.developersdex.com ***
            > Don't just participate in USENET...get rewarded for it![/color]


            Comment

            • Kamlesh Rao

              #7
              Re: How to use QBColor in VB.NET?

              Hi Ken/Cor,

              I tried both of your code. The code is running without any errors. But
              I want the Form Background color to change randomly on every click of
              the Command Button.

              Right now, with your sample code, it is showing only one single color.
              The color is not changing on every click of the commandbutton.

              Regards,
              Kamlesh


              *** Sent via Developersdex http://www.developersdex.com ***
              Don't just participate in USENET...get rewarded for it!

              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: How to use QBColor in VB.NET?

                * "Tom Spink" <thomasdotspink at@ntlworlddotc om> scripsit:[color=blue]
                > Hi, (untested) try:
                >
                > Me.BackColor = Color.FromARGB( QBColor(Rnd * 14))[/color]

                'FromArgb'.

                :->

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

                Comment

                Working...