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

2016-01-29 12:43 12 1 收藏

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

【 tulaoshi.com - ASP.NET 】

崔占民在其文章《用代码实现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

来源:http://www.tulaoshi.com/n/20160129/1487329.html

延伸阅读
首先是实现ListView控件的自定义排序,订阅ListView控件的ColumnClick事件 private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) { if (this.listView1.Columns[e.Column].Tag == null) this.listView1.Columns[e.Column].Tag = true; bool tabK = (bool)this.listView1.Columns[e.Column].Tag; if (tabK) ...
Android本身为ListView提供了几个方便的Adapter,比如ArrayAdapter、SimpleCurrentAdapter等等。但是为了实现更复杂的列表视图和控制,一般都要继承BaseAdapter来实现自己的Adapter。 我需要的ListView是如图一样的实现SD卡资源文件浏览列表,每个列表项由一个ImageView、TextView、CheckBox组成,并且要求当整个列表中有一个或一个以上的Chec...
标签: ASP
<html <head <titleUntitled Document</title <meta http-equiv="Content-Type" content="text/html; charset=gb2312" <style .t1 {background-color:#336699;text-align:center} .t2 {background-color:#ffcc00;text-align:center} </style </head <body bgcolor="#FFFFFF" text="#000000" <table id="table...
 Private Sub filllistboxwithcolors()         Me.ListBox1.DrawMode = DrawMode.OwnerDrawFixed         Me.ListBox1.ItemHeight = 24         '避免闪烁       &nbs...
标签: Web开发
应用背景 当用户需要某项功能时要填写一些表单信息,在填写完成并提交后,该部分信息是不允许再次修改的。表单包含TextBox、DropDownList、CheckBox等控件。 需求实现 第一种方案,绑定用户填写的数据时,设置控件的Enable属性为False。如果页面的表单数较少时可采用这样的方法,但是如果在表单较多的情况下则并不是更好的方法。 第...

经验教程

820

收藏

50
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部