【问题标题】:Windows form controls become grey overlayWindows 窗体控件变为灰色覆盖
【发布时间】:2015-06-07 06:42:25
【问题描述】:

我在 vb.net 中创建了一个 winform 应用程序,它包含一个父容器和其他子窗体。当其中一个包含具有某些单元格格式的数据网格视图的子窗体时,加载其他控件时变为灰色覆盖。

注意:gridview 是使用数据库中的数据创建的,颜色是根据单元格中的值应用的。使用 cellformating 方法改变颜色。我试过双缓冲..但它没有帮助。红色圆圈为标签,绿色为按钮。

找到下面的单元格格式代码:

  Private Sub dataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dataGridView1.CellFormatting
    Try
        Dim i As Integer
        For i = 0 To dataGridView1.RowCount
            If (i = (dataGridView1.RowCount)) Then
                Exit For
            Else
                Dim dt As DateTime = DateTime.Parse(dataGridView1.Rows(i).Cells(6).Value.ToString())
                dt = dt.AddHours(12)
                Dim ts As TimeSpan = dt.Subtract(DateTime.Now)
                Dim s As String = dataGridView1.Rows(i).Cells(7).Value.ToString()
                If s = "Ready to Collect" Then
                    dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.LimeGreen
                    dataGridView1.Rows(i).Cells(8).Value = "-----"
                ElseIf s = "Completed" Then
                    dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.GreenYellow
                    dataGridView1.Rows(i).Cells(8).Value = "-----"
                ElseIf s = "Out of Stock" Then
                    dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.Red
                    dataGridView1.Rows(i).Cells(8).Value = "-----"
                ElseIf s = "Sent" Then
                    dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.OrangeRed
                    If ts.CompareTo(TimeSpan.Zero) < 0 Then
                        dataGridView1.Rows(i).Cells(8).Value = "Process Immediately"
                        dataGridView1.Rows(i).Cells(8).Style.BackColor = Color.OrangeRed
                    Else
                        dataGridView1.Rows(i).Cells(8).Value = String.Format("{0:D2}:{1:D2}", ts.Hours, ts.Minutes)
                    End If
                ElseIf s = "Cancelled" Then
                    dataGridView1.Rows(i).Cells(7).Style.BackColor = Color.White
                    dataGridView1.Rows(i).Cells(8).Value = "-----"
                End If
            End If
        Next

    Catch ex As Exception
        System.Diagnostics.Trace.TraceError(ex.Message)
    End Try

【问题讨论】:

  • 显示代码,如何为 datagridview 和其他控件设置颜色
  • 我认为父窗体 backColor 是灰色的,子控件是透明的!当控件背景色透明时,该控件将父颜色设置为自身!控制背景颜色的测试不透明
  • 不,是控制灯....
  • 对我来说,BackColor 和 ForeColor 的控件看起来都是相同的颜色。
  • 不..它不是...当我将表单拖到另一个位置时,它变得正常...

标签: vb.net winforms gridview


【解决方案1】:

检查DoEvents。也许这对你有帮助。

【讨论】:

  • DoEvents 是邪恶的。它带来的问题多于解决的问题。它在 VB6 中被广泛使用,但在 VB.Net 编程中没有位置。根本不需要它。原始发布者不应使用 DoEvents,而应将任何长时间运行的代码放在后台工作程序中,以便 UI 可以继续响应。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多