一、改變顏色在VB6的ListView控制元件中,可以改變專案及其子項的前景色、背景色。實現方法如下(1)在窗體上佈置一個ListView控制元件(2)窗體程式碼如下Option ExplicitPrivate Sub Form_Load()Dim itemX As ListItemWith ListView1.View = lvwReport.ColumnHeaders.Add , , "類別".ColumnHeaders.Add , , "品名1".ColumnHeaders.Add , , "品名2"Set itemX = .ListItems.Add(, , "水果")itemX.SubItems(1) = "蘋果"itemX.SubItems(2) = "香蕉"ChangeForeColor itemX, &H8000& "墨綠色Set itemX = .ListItems.Add(, , "飲料")itemX.SubItems(1) = "果汁"itemX.SubItems(2) = "可樂"ChangeForeColor itemX, vbRed "紅色Set itemX = .ListItems.Add(, , "文具")itemX.SubItems(1) = "鉛筆"itemX.SubItems(2) = "橡皮"ChangeForeColor itemX, vbBlue "藍色End WithEnd Sub"-------------------------------------" 修改ListView 項的前景色顏色"-------------------------------------Private Sub ChangeForeColor( _ByVal item As ListItem, _ByVal NewColor As Long)"設定項的顏色 item.ForeColor = NewColor"設定所有子項的顏色Dim subItem As ListSubItemFor Each subItem In item.ListSubItemssubItem.ForeColor = NewColorNextEnd Sub(3)執行效果二、改變字型ListView控制元件中,ListItem以及ListSubItem中沒有字型屬性,所以無法改變單獨某個項或子項的字型;只能改ListView控制元件的字型。執行效果
一、改變顏色在VB6的ListView控制元件中,可以改變專案及其子項的前景色、背景色。實現方法如下(1)在窗體上佈置一個ListView控制元件(2)窗體程式碼如下Option ExplicitPrivate Sub Form_Load()Dim itemX As ListItemWith ListView1.View = lvwReport.ColumnHeaders.Add , , "類別".ColumnHeaders.Add , , "品名1".ColumnHeaders.Add , , "品名2"Set itemX = .ListItems.Add(, , "水果")itemX.SubItems(1) = "蘋果"itemX.SubItems(2) = "香蕉"ChangeForeColor itemX, &H8000& "墨綠色Set itemX = .ListItems.Add(, , "飲料")itemX.SubItems(1) = "果汁"itemX.SubItems(2) = "可樂"ChangeForeColor itemX, vbRed "紅色Set itemX = .ListItems.Add(, , "文具")itemX.SubItems(1) = "鉛筆"itemX.SubItems(2) = "橡皮"ChangeForeColor itemX, vbBlue "藍色End WithEnd Sub"-------------------------------------" 修改ListView 項的前景色顏色"-------------------------------------Private Sub ChangeForeColor( _ByVal item As ListItem, _ByVal NewColor As Long)"設定項的顏色 item.ForeColor = NewColor"設定所有子項的顏色Dim subItem As ListSubItemFor Each subItem In item.ListSubItemssubItem.ForeColor = NewColorNextEnd Sub(3)執行效果二、改變字型ListView控制元件中,ListItem以及ListSubItem中沒有字型屬性,所以無法改變單獨某個項或子項的字型;只能改ListView控制元件的字型。執行效果