Results 1 to 8 of 8

Thread: Convert form.backcolor value to long?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2004
    Posts
    56

    Angry Convert form.backcolor value to long?

    Hello. I am trying to use the CreateSolidBrush API to give my form's menu a particular color (in my case I just want to set the menu's color to the form's background color - right now the menu is white).

    CreateSolidBrush expects a long value for the color. However, the form's .backcolor value in the properties window is some weird system color value, in this case "&H8000000F&". How do I convert this value to the long value I need for the CreateSolidBrush API? Is there another API call I need to use that retrieves the form's background color as a long value?

    BTW I'm using VB6.

    Many thanks in advance...

  2. #2
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Convert form.backcolor value to long?

    Hmmmmnnnn.... will the CLNG help?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2004
    Posts
    56

    Re: Convert form.backcolor value to long?

    I tried that but of course it didn't work Why does a seemingly easy thing have to be so difficult?

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Convert form.backcolor value to long?

    Add this code to your form.

    The "weird" value is the hexadecimal representation of the back colour. This code shows the hex and decimal representations.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   MsgBox Hex(Me.BackColor) & " as a decimal is " & Me.BackColor, , "Form Back Colour"
    5. End Sub
    This world is not my home. I'm just passing through.

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Convert form.backcolor value to long?

    All colours that a user can change via the Windows Display Properties are System Colours. To get the actual colour, you need to find the color index and then pass that to the GetSysColor API.

    Check this thread for some code

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2004
    Posts
    56

    Question Re: Convert form.backcolor value to long?

    Thanks brucevde. Oe last thing. That article mentions:

    "The last byte of a system colour constant contains the index you need. So for &H8000000F&, it would be Hex F = 15. For Button Text (ForeColor property, typically &H80000012&) it would be Hex 12 (18)."

    How do you extract "the last byte" of the system color? I realize I could just type Hex(F) or Hex(12) - but of course I'd like to dynamically extract that piece of info. Thanks again...

  7. #7
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Convert form.backcolor value to long?

    VB Code:
    1. Debug.Print Me.BackColor And &HFF
    This world is not my home. I'm just passing through.

  8. #8
    Addicted Member Max_aka_NOBODY's Avatar
    Join Date
    Jul 2004
    Location
    Amman, Jordan
    Posts
    179

    Re: Convert form.backcolor value to long?

    How do you extract "the last byte" of the system color? I realize I could just type Hex(F) or Hex(12) - but of course I'd like to dynamically extract that piece of info. Thanks again...
    Like Tris posted, but I'd like to note that Hex() is for converting decimal to Hex, not the other way around.

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