• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

VB中的涂色

发布: 2007-6-21 21:57 | 作者:   | 来源:   | 查看: 15次 | 进入软件测试论坛讨论

领测软件测试网

   


  Colours in VB

VB provides an easy RGB function to convert three colours into a RGB colour code. However, it provides no way of converting it back to the three colours. It also provides no support for HTML colour codes used on web pages. We decided to write some functions to convert HTML colour codes to and from RGB codes, and also functions to break them back down into their constituent colours.

Public Const RedPart = 0
Public Const GreenPart = 1
Public Const BluePart = 2

Public Function HTML(Red As Integer, Green As Integer, Blue As Integer) As String

HTML = ""
If Len(Hex$(Red)) = 1 Then
HTML = HTML & "0" & Hex$(Red)
Else
HTML = HTML & Hex$(Red)
End If
If Len(Hex$(Green)) = 1 Then
HTML = HTML & "0" & Hex$(Green)
Else
HTML = HTML & Hex$(Green)
End If
If Len(Hex$(Blue)) = 1 Then
HTML = HTML & "0" & Hex$(Blue)
Else
HTML = HTML & Hex$(Blue)
End If

End Function

Public Function UnRGB(RGBCol As Long, Part As Integer) As Integer
注释:Part: 0=Red, 1=Green, 2=Blue

Select Case Part
Case 0
UnRGB = RGBCol And &HFF
注释:mask 000000000000000011111111 and shift bits right
Case 1
UnRGB = (RGBCol And &HFF00) / &HFF
注释:mask 000000001111111100000000 and shift bits right
Case 2
UnRGB = (RGBCol And &HFF0000) / &HFFFF
注释:mask 111111110000000000000000 and shift bits right
End Select

End Function

Public Function UnHTML(HTMLCol As String, Part As Integer) As Integer
注释:Part: 0=Red, 1=Green, 2=Blue

Select Case Part
Case 0
UnHTML = (CLng("&H" & HTMLCol) And &HFF0000) / &HFFFF
注释:mask 111111110000000000000000 and shift bits right
Case 1
UnHTML = (CLng("&H" & HTMLCol) And &HFF00) / &HFF
注释:mask 000000001111111100000000 and shift bits right
Case 2
UnHTML = CLng("&H" & HTMLCol) And &HFF
注释:mask 000000000000000011111111 and shift bits right
End Select

End Function

Public Function RGB2HTML(RGBCol As Long) As String

RGB2HTML = HTML(UnRGB(RGBCol, RedPart),
UnRGB(RGBCol, GreenPart), UnRGB(RGBCol, BluePart))
End Function

Public Function HTML2RGB(HTMLCol As String) As Long
HTML2RGB = RGB(UnHTML(HTMLCol, RedPart), UnHTML(HTMLCol, _
GreenPart), UnHTML(HTMLCol, BluePart))
End Function

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网