Private Sub Form_Load() MSHFlexGrid1.Row = 3 MSHFlexGrid1.Col = 1 MSHFlexGrid1.ColSel = MSHFlexGrid1.Cols - 1 MSHFlexGrid1.RowSel = MSHFlexGrid1.Rows - 1 MSHFlexGrid1.CellBackColor = vbRed MSHFlexGrid1.BackColorSel = vbRed End Sub
把改底色的语句写成一个过程,就可以方便调用了,如:Sub ChangeGridColor(LeftC as long, RightC as long, TopR as long, ButtomR as long, Color as long) dim I as long dim L as long with grid1 .visible=false for I= leftc to rightc .Col=I for L=topr to ButtomR .Row = L .CellForeColor = Color next next .visible=true end with end sub这样就简单多了: ChangeGridColor 1,3,8,12,vbred
循环写成一个sub,然后每次调用就可以了Sub ChangeGridColor(LeftC as long, RightC as long, TopR as long, ButtomR as long, Color as long) dim I as long dim L as long with grid1 .visible=false for I= leftc to rightc .Col=I for L=topr to ButtomR .Row = L .CellForeColor = Color next next .visible=true end with end sub
MSHFlexGrid1.Row = 3
MSHFlexGrid1.Col = 1
MSHFlexGrid1.ColSel = MSHFlexGrid1.Cols - 1
MSHFlexGrid1.RowSel = MSHFlexGrid1.Rows - 1
MSHFlexGrid1.CellBackColor = vbRed
MSHFlexGrid1.BackColorSel = vbRed
End Sub
dim I as long
dim L as long
with grid1
.visible=false
for I= leftc to rightc
.Col=I
for L=topr to ButtomR
.Row = L
.CellForeColor = Color
next
next
.visible=true
end with
end sub这样就简单多了: ChangeGridColor 1,3,8,12,vbred
dim I as long
dim L as long
with grid1
.visible=false
for I= leftc to rightc
.Col=I
for L=topr to ButtomR
.Row = L
.CellForeColor = Color
next
next
.visible=true
end with
end sub
应该是cellbackcolor吧