我在 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))
后来我意识到这可能不是最好的方法,所以我想知道你们将如何处理和解决这个问题?正如我的个人资料上所说,我来这里是为了学习,并且当我将来需要解决类似问题时,我会考虑更有经验的开发人员的任何建议