Windows窗体控件变为灰色叠加

时间:2015-06-07 06:42:26

标签: vb.net winforms gridview

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

Screenshot

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

找到以下代码以进行单元格格式化:

  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

1 个答案:

答案 0 :(得分:0)

检查DoEvents。也许这有助于你。