实现ListView控件的行间隔颜色的优化代码

love康然

love康然

2016-01-29 12:43

实现ListView控件的行间隔颜色的优化代码,实现ListView控件的行间隔颜色的优化代码
崔占民在其文章《用代码实现ListView控件的行间隔颜色》中给出了实现代码,经过笔者测试,发现有如下bug:
首先,虽然可以看到背景色间隔,但是条块的高度等于原始picGreenBar的高度。应该在autoredraw属性设置为true之前,将height属性设置为一个最小值,比如1。
另外,listview的属性要修改一下: ... ListView1.View = lvwReport ListView1.FullRowSelect = True ListView1.GridLines = True picGreenbar.Height = 1 '添加一些实验数据 ....
为方便读者,将全部代码公布如下(关键代码来自《用代码实现ListView控件的行间隔颜色》):
--------------------------------
VERSION 5.00Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"Begin VB.Form Form1 Caption = "Form1" ClientHeight = 5400 ClientLeft = 60 ClientTop = 345 ClientWidth = 5940 LinkTopic = "Form1" ScaleHeight = 5400 ScaleWidth = 5940 StartUpPosition = 3
Begin VB.PictureBox picGreenbar Height = 1695 Left = 120 ScaleHeight = 1282.353 ScaleMode = 0 'User ScaleWidth = 4635 TabIndex = 1 Top = 3480 Width = 4695 End Begin MSComctlLib.ListView ListView1 Height = 3255 Left = 120 TabIndex = 0 Top = 120 Width = 4695 _ExtentX = 8281 _ExtentY = 5741 View = 3 Sorted = -1 'True LabelWrap = -1 'True HideSelection = -1 'True FlatScrollBar = -1 'True FullRowSelect = -1 'True GridLines = -1 'True _Version = 393217 ForeColor = -2147483640 BackColor = -2147483643 BorderStyle = 1 Appearance = 1 NumItems = 0 EndEndAttribute VB_Name = "Form1"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption Explicit

Private Sub Form_Load()
Dim j As Integer Dim itmX As ListItem ListView1.ColumnHeaders.Add , , "This is Just a Simple Example" ListView1.ColumnHeaders(1).Width = 3000 ListView1.View = lvwReport ListView1.FullRowSelect = True ListView1.GridLines = True picGreenbar.Height = 1 '添加一些实验数据 For j = 1 To 33 Set itmX = ListView1.ListItems.Add() itmX.Text = "This is item number " & CStr(j) Next j Call ColorListView(Me.ListView1, Me.picGreenbar)
End Sub
Private Sub Form_Resize() ListView1.Width = Me.ScaleWidthEnd SubPrivate Sub ColorListView(ListView1 As ListView, picGreenbar As PictureBox) Dim i As Integer Dim iFontHeight As Long Dim iBarHeight As Integer Dim ColHead As ColumnHeader 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), &HE7E8FC, BF picGreenbar.Line (0, 1)-(1, 2), RGB(0, 255, 0), BF '====== ListView1.PictureAlignment = lvwTile ListView1.Picture = picGreenbar.ImageEnd Sub
展开更多 50%)
分享

猜你喜欢

实现ListView控件的行间隔颜色的优化代码

电脑网络
实现ListView控件的行间隔颜色的优化代码

在DElphi中的DataGrid怎样使它显示的行间隔改变颜色

编程语言 网络编程
在DElphi中的DataGrid怎样使它显示的行间隔改变颜色

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

android下拉刷新ListView的介绍和实现代码

编程语言 网络编程
android下拉刷新ListView的介绍和实现代码

ListView异步加载图片实现思路(优化篇)

编程语言 网络编程
ListView异步加载图片实现思路(优化篇)

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

javascript实现的listview效果

Web开发
javascript实现的listview效果

jquery 分页控件实现代码

Web开发
jquery 分页控件实现代码

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Windows Sockets API实现网络异步通讯

Windows Sockets API实现网络异步通讯

主页设计中配色方案的使用(上)

主页设计中配色方案的使用(上)
下拉加载更多内容 ↓