【问题标题】:vb.net controls set propertyvb.net 控件设置属性
【发布时间】:2016-11-14 07:43:41
【问题描述】:

你能帮我解决我在 vb.net 上的问题吗 我想通过使用控件检查表单上的所有组件来更改一个或多个 datagridview 的背景颜色..

For Each ctrl In ctrlParent.Controls
    If ctrl.GetType Is GetType(DataGridView) Then
        ....
    End If
Next

如果我使用 ctrl.BackColor = Color.Black,那就没有任何改变。但如果我使用 ctrl.Backgroundcolor = Color.Black 显示错误:'Backgroundcolor' 不是 'System.Windows.Forms.Control' 的成员 任何的想法?

我可以访问控制属性来更改 datagridview 的“背景颜色”属性吗?
还是别的?



注意:ctrl.ForeColor = Color.Black -> 成功改变datagridview的字体颜色

【问题讨论】:

  • 控件没有 BackgroundColor 属性!它有一个BackColor
  • 是的,我知道...有什么办法解决这个问题吗?
  • 使用 Control.BackColor... 而不是 BackgroundColor
  • 正如我之前所说,使用 Control.BackColor 进行 datagridview 没有发生任何事情
  • 请阅读您的问题并正确编辑,使用正确的文字、背景色或背景色...

标签: vb.net datagridview


【解决方案1】:

您可以在循环中将控件类型直接过滤为DataGridView
然后相应地设置BackgroundColor

For Each ctrl In ctrlParent.Controls.OfType(Of DataGridView)
    ctrl.BackgroundColor = Color.Black
Next

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-17
    • 1970-01-01
    • 2014-10-08
    相关资源
    最近更新 更多