CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: rgb

  1. #1
    Join Date
    Feb 1999
    Posts
    11

    rgb



    How do I get the RGB values from the color dialog box once I've opened it ?

    I need to use those values not just the 16 million number value. Thanks

  2. #2
    Join Date
    Feb 1999
    Posts
    11

    Re: rgb



    Never Mind Answered my own question!

    Thanks anyway here it is if anyone interested.


    Used this formula:


    'General Declarations...


    Function GetRGB(RGBval As Long, Num As Integer) As Integer

    ' Check if Num, RGBval are valid.

    If Num > 0 And Num -1 And RGBval < 16777216 Then

    GetRGB = RGBval \ 256 ^ (Num - 1) And 255

    Else:

    ' Return True (-1) if Num or RGBval are invalid.

    GetRGB = True

    End If

    End Function


    'On a Form placed Label object to get color from Commondialog,

    'then captured the RGB from the label backcolor...


    Private Sub Command1_Click()

    CommonDialog1.CancelError = True

    CommonDialog1.Flags = &H2 'full open

    CommonDialog1.ShowColor

    Label1.BackColor = CommonDialog1.Color

    Text1 = GetRGB(Label1.BackColor, 1) 'Red

    Text2 = GetRGB(Label1.BackColor, 2) 'Green

    Text3 = GetRGB(Label1.BackColor, 3) 'Blue

    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured