Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5921
  • Last Modified:

How to convert rgb to long color in vb?

I'm using some shapes in my vb form.

I need to change background color, but vb use long color like this &H00E0E0E0&
While I use photoshop to get my color right in rgb color and html color #FFFFFF

Is there any tool to convert rgb or html color to vb color?

I know I can use command like:
s1.BackColor = RGB(239, 231, 222)
I don't like it, i want in design time.
0
dodyrw
Asked:
dodyrw
  • 3
  • 3
  • 2
  • +1
1 Solution
 
stewiCommented:
iColor=&hccccff 'the color in hex same syntax as html
s1.BackColor=rgb((iColor And &HFF),((iColor And &HFF00&) \ 256),((iColor And &HFF0000) \ 65536))

Reguards
Stewi
0
 
vwareCommented:
You can use either of those 2, simply create a new form, place the following code into it. Adjust the parameters to your needs.

Private Sub Form_Load()
    MsgBox GetVBFromRGB(10, 10, 10)
End Sub

Private Function GetHexFromRGB(ByVal RVal As Byte, ByVal GVal As Byte, ByVal BVal As Byte) As String
    Dim TmpHex As String
   
    TmpHex = Left("0" & Hex(BVal), 2) & _
             Left("0" & Hex(GVal), 2) & _
             Left("0" & Hex(RVal), 2)
    GetHexFromRGB = "&H" & TmpHex & "&"
End Function

Private Function GetVBFromRGB(ByVal RVal As Byte, ByVal GVal As Byte, ByVal BVal As Byte) As String
    Dim TmpHex As String
   
    TmpHex = Left("0" & Hex(RVal), 2) & _
             Left("0" & Hex(GVal), 2) & _
             Left("0" & Hex(BVal), 2)
    GetVBFromRGB = "#" & TmpHex
End Function
0
 
dodyrwAuthor Commented:
Sorry I think that is not the answer i need.
&H00E0E0E0& is not hex.

anyone?
HTML to VB color
or RGB to VB color is fine.

anyway, thanks for your help guys.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
stewiCommented:
... &H00E0E0E0& is not hex...
yes it is...
&H is the VB-way to say its a hex
00 is just zeros
E0 if the hex for blue
E0 is the hex for green
E0 is the hex for red
& is the VB-way for long integer

Reguard
Stewi
0
 
vwareCommented:
sorry to disappoint you dodyrw, but this IS hex... stewi explained that pretty nicely... apart from that, you can still use the GetVBFromRGB function, which converts RGB to VB. just in case you dont trust the Hex that comes from the GetHexFromRGB function...
0
 
dodyrwAuthor Commented:
:) sorry I'm to0 haste, lol
it's hex.   :)

vb use 8 digit hex: &H00E0E0E0&
but those codes produce only 6 digits.


Got it! VB use reverse RGB
#EFE7DE
--> &H00DEE7EF

:D
thanks.
0
 
stewiCommented:
Yes, now your on the right track.

Stewi
0
 
vwareCommented:
thats why i built the example i posted like this... so you could see the re-ordering of the values...
0
 
MikeEastCommented:
Hi all..

I guess this is the answer to all doubts:

myControl.BackColor = System.Drawing.ColorTranslator.FromHtml("#ffffff")

That is for VB.NET of course, but I just wanted to add the comment here, since I found this page looking for that very answer...

::m
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now