【问题标题】:The picturebox be hidden during execute a long loop在执行长循环期间隐藏图片框
【发布时间】:2020-04-08 13:35:31
【问题描述】:

在执行我的代码期间,我正在显示一个包含 gif 照片的图片框:

Me.PicLoading.Visible = True
Call xCLS.MyCodes_GetID("tbl_cities", Me.t1)
Me.PicLoading.Visible = False

这工作得很好,但是当我使用长“For Loop”的长过程时,PictureBox 框变得隐藏,并且在执行循环后图像框变得可见。 这个问题只发生在循环中。

接下来的代码是循环:

Public Sub MyCodes_GetID(ByVal TblName As String, ByVal TxT As TextBox)
    Dim xCount, i As Integer
    Dim xDtCount As DataTable = New DataTable()

    MyCodes_Fill_DataTable("Select ID From " & TblName & " Order By ID", xDtCount)
    xCount = Convert.ToInt32(xDtCount.Rows.Count)

    For i = 1 To xCount
        Dim xCountID As Byte
        Dim xDtCountID As DataTable = New DataTable()
        MyCodes_Fill_DataTable("Select ID From " & TblName & " Where ID = " & i & "", xDtCountID)
        xCountID = Convert.ToInt32(xDtCountID.Rows.Count)
        If xCountID = 0 Then
            GoTo Line1
        End If
    Next
Line1:
        TxT.Text = CStr(i)
    End Sub

任何cmets

【问题讨论】:

  • 在循环中,你没有对图片框做任何事情。你可能应该用Exit For 替换那个GoTo 语句。
  • @preciousbetine 我知道,我试过Exit For,得到了同样的结果
  • @preciousbetine 我直接从属性设置图像而不是通过代码

标签: vb.net for-loop


【解决方案1】:

UI 线程忙于处理您的代码,无法显示PictureBox。您需要先调用它的Refresh 方法,然后才能强制它重新绘制。

出于同样的原因,您的 GIF 不会生成动画。异步执行长时间运行的任务。如果你不知道怎么做,是时候学习了。这超出了这个问题的范围。

【讨论】:

  • 从 GOTO 声明来看,我想说现在是 OP 研究构建 .NET 特定 VB 代码的好时机。
猜你喜欢
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
  • 2021-06-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-14
相关资源
最近更新 更多