首先在窗口中添加一个ListView控件,方法:菜单->工程->部件->Microsoft Window Common Control 6.0 (后面为版本号)。再添加一个Picture控件,改名为picGreenbar。
实现的代码如下:
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Dim iFontHeight As Long
Dim iBarHeight As Integer
Dim j As Integer
Dim itmX As ListItem
Dim ColHead As ColumnHeader
ListView1.ColumnHeaders.Add , , "This is Just a Simple Example"
ListView1.ColumnHeaders(1).Width = 3000
'添加一些实验数据
For j = 1 To 33
Set itmX = ListView1.ListItems.Add()
itmX.Text = "This is item number " & CStr(j)
Next j
Me.ScaleMode = vbTwips
picGreenbar.ScaleMode = vbTwips
picGreenbar.BorderStyle = vbBSNone
picGreenbar.AutoRedraw = True
picGreenbar.Visible = False
picGreenbar.Font = ListView1.Font
iFontHeight = picGreenbar.TextHeight("b") + Screen.TwipsPerPixelY
iBarHeight = (iFontHeight * 1)
picGreenbar.Width = ListView1.Width
'======
picGreenbar.Height = iBarHeight * 2
picGreenbar.ScaleMode = vbUser
picGreenbar.ScaleHeight = 2
picGreenbar.ScaleWidth = 1
'draw the actual bars
picGreenbar.Line (0, 0)-(1, 1), vbWhite, BF
picGreenbar.Line (0, 1)-(1, 2), RGB(227, 241, 226), BF
'======
ListView1.PictureAlignment = lvwTile
ListView1.Picture = picGreenbar.Image
End Sub
代码量不多,不过很实用。
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073