【问题标题】:C# datagridview printing color every secondC# datagridview 每秒打印颜色
【发布时间】:2023-03-18 13:37:02
【问题描述】:
    excel = Workbook.Open("1.xls");
    sheeticerik = excel.Worksheets[0];
    for (int k = 0; k < sutun; k++)
        for (int i = 0; i < satir; i++)
        {
            string a = sheeticerik.Cells[i, k].StringValue;
            if (a.Contains("X"))
            {
                dataGridView1.Rows[x1].Cells[y1].Style.BackColor = System.Drawing.Color.Red;
                System.Threading.Thread.Sleep(1000);
                dataGridView1.Refresh();

            }
        }

我想每秒打印颜色到datagridview。我写了这段代码。但它不起作用。因为程序loop.countX1000秒等待并立即打印颜色。不是连续打印。我该怎么办?

解决方案[编辑]:

-在表单中添加 Timer 控件。 (它在组件类别中)

-将其Interval属性设置为45000(值代表毫秒)

-在表单设计器中或在代码中的某处将计时器的 Enabled 属性设置为 True。

-为定时器的Tick事件添加处理程序(可以通过双击定时器来获取)

-在 Tick 处理程序中,更新您的 dataGridView

private void timer1_Tick(object sender, EventArgs e)
{
    // Update DataGridView
}

并使用,timer1.Start();...

【问题讨论】:

  • 你走错路了。您需要一个计时器来更新数据网格。
  • 谢谢你的人......定时器的工作!

标签: c# datagridview


【解决方案1】:

与其尝试在计时器上打印颜色,不如尝试在 DataGridView 的 Render() 事件期间打印颜色。您的屏幕闪烁也可能会少得多。

【讨论】:

    猜你喜欢
    • 2015-09-22
    • 1970-01-01
    • 2014-12-06
    • 1970-01-01
    • 2021-11-19
    • 2014-12-14
    • 2016-10-15
    • 2017-11-20
    • 2018-12-15
    相关资源
    最近更新 更多