commondialog中的color取出来后,怎么不一样?

liuguozhong 2005-01-20 02:53:27
我用commondialog.color取出来的值怎么是8位?如:12453343
我们平常用色值的不是6位的16进制的数么?如:#ff6600
我要怎样才能转换成下面的格式呢?
...全文
62 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuguozhong 2005-01-20
  • 打赏
  • 举报
回复
thanks~~
viena 2005-01-20
  • 打赏
  • 举报
回复
给你写了个函数
Function getStrColor(ByVal lngColor As Long) As String
Dim strRed As String, strGreen As String, strBlue As String
strRed = Hex(lngColor And 255)
If Len(strRed) = 1 Then strRed = "0" & strRed
strGreen = Hex(lngColor And 65280)
If Len(strGreen) = 3 Then
strGreen = "0" & Left(strGreen, 1)
Else
strGreen = Left(strGreen, 2)
End If
strBlue = Hex(lngColor And 16711680)
If Len(strBlue) = 5 Then
strBlue = "0" & Left(strBlue, 1)
Else
strBlue = Left(strBlue, 2)
End If
getStrColor = "#" & strRed & strGreen & strBlue
End Function

试一下:
Private Sub Form_Load()
Dim lngColor As Long
lngColor = 12453343
Debug.Print getStrColor(lngColor)
End Sub
liuguozhong 2005-01-20
  • 打赏
  • 举报
回复
我要自动转成6位的16进制如:#ff6600的格式。
用于显示指定颜色并转换成网页中能显示的颜色。
viena 2005-01-20
  • 打赏
  • 举报
回复
颜色一般是Long型数,转换成“6位的16进制的数么?如:#ff6600”做什么用呢?

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧