VB颜色和RGB色互相转换头疼了我好一段时间,如今找到解决办法了
特别贴出来与大家共享
Type RGB
Red As String
Green As String
Blue As String
End Type
Public Function ColorToRGB(ByVal dwColor As Long) As RGB
Dim clrHex As String
clrHex = Replace(Format(Hex$(dwColor),"@@@@@@")," ","0")
ColorToRGB.Red = Mid$(clrHex,5,2)
ColorToRGB.Green = Mid$(clrHex,3,2)
ColorToRGB.Blue = Mid$(clrHex,1,2) '
End Function
Public Function RgbToColor(ByVal rColor As String)
Dim tempColor As String,RedColor As String,GreenColor As String,BlueColor As String
tempColor = Replace(rColor,"0x","")
RedColor = Mid(tempColor,2)
GreenColor = Mid(tempColor,2)
BlueColor = Mid(tempColor,2)
RgbToColor = RGB(Val("&H" & RedColor),Val("&H" & GreenColor),Val("&H" & BlueColor))
End Function
说明===============
ColorToRGB 作用是将VB中的颜色转换成RGB的颜色 比如 &H00FFFFFF& 会变成FFFFFF
RgbToColor 作用是将16进制的颜色 如FFFF00 转换成对应的十进制 再通过VB自带的RGB函数 转换成VB需要的颜色
原文链接:/vb/262686.html