【发布时间】:2013-02-26 09:00:10
【问题描述】:
我在 VB 中工作,试图设置 Datagridview 的单元格背景颜色,但找不到让我实现该功能的内置函数,所以我最终将 Alpha、Red、Green 和 Blue 的值存储在变量中,然后使用 `Color.FromArgb' 设置背景颜色
这是我使用的代码,它可以工作:
currentval = ""
A = ""
R = ""
G = ""
B = ""
For Each s As Char In reader.ReadElementString("cell")
If s = " " Then
currentval = ""
GoTo nextSS
End If
If Not s = "," Then
currentval = currentval & s
End If
If s = "," Then
If A = "" Then
A = currentval
currentval = ""
GoTo nextSS
End If
If Not A = "" And R = "" Then
R = currentval
currentval = ""
GoTo nextSS
End If
If Not A = "" And Not R = "" And G = "" Then
G = currentval
currentval = ""
GoTo nextSS
End If
End If
nextSS:
Next s
If Not A = "" And Not R = "" And Not G = "" And B = "" Then
B = currentval
currentval = ""
End If
Grid.Rows(i).Cells(y).Style.BackColor = Color.FromArgb(CInt(A), CInt(R), CInt(G), CInt(B))
我后来意识到这可能不是最好的方法,所以我想知道你们将如何处理和解决这个问题?正如我的个人资料上所说,我来这里是为了学习,并且当我将来需要解决类似问题时,我们会考虑更有经验的开发人员的任何建议
【问题讨论】:
标签: vb.net visual-studio-2010 datagridview