代码之家  ›  专栏  ›  技术社区  ›  ScottishTapWater

为什么图片框不更新?

  •  0
  • ScottishTapWater  · 技术社区  · 9 年前

    我有一个列表框,当选定的索引发生变化时,它会解析该索引中的文本以获取一个关键字,然后使用该关键字显示该索引的相关图像。至少应该如此。

    这个 updatePics 当我第一次向列表框中添加一个新项时,子例程会工作,但当我在更改索引时调用它时,它不会工作。

    这个 parseLstBoxItem 函数有效,我已使用消息框验证了这一点。

    相关密钥和列表位于 jobsDict 字典,使用autos验证。

    我甚至尝试过使用断点单步执行,但我无法确定出了什么问题。因此,任何帮助都将非常感谢!

    相关子系统/功能如下:

    更改所选收件箱时更新所有内容:

        Private Sub lstbxJobs_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstbxJobs.SelectedIndexChanged
        currentJob = parseLstBxItem(lstbxJobs.SelectedIndex)
        MsgBox(parseLstBxItem(lstbxJobs.SelectedIndex))
        updatePics()
        updateTicks(JobsDict(currentJob).stage)
        populateList()
    End Sub
    

    更新下面的图片框和数字字幕:

    Public Sub updatePics()
        udImage.Maximum = JobsDict(currentJob).images.Count
        udImage.Minimum = 1
        udImage.Value = 1
        pctJobPics.ImageLocation = JobsDict(currentJob).images(0)
    End Sub
    

    字典定义为:

     Property JobsDict As New Dictionary(Of String, job)
    

    它被填充在该子例程中(从不同的形式):

     Public Sub initJob(ID As String, notes As String, product As String, eta As Integer)
        Orders.JobsDict.Add(ID, New job)
        Orders.JobsDict(ID).ID = ID
        Orders.JobsDict(ID).notes = notes
        Orders.JobsDict(ID).product = product
        Orders.JobsDict(ID).stage = 0
        Orders.JobsDict(ID).images = imgList
        Orders.JobsDict(ID).ETA = eta
        Orders.JobsDict(ID).bumped = False
        Orders.chkItemStage.SetItemChecked(0, True)
    
    End Sub
    

    job 是自定义类,定义为:

    Public Class job
    Property ID As String
    Property product As String
    Property ETA As Integer
    Property stage As Integer
    Property notes As String
    Property images As New List(Of String)
    Property bumped As Boolean
    
    Public Sub nextStage()
        If stage < 4 Then
            stage += 1
            Orders.updateTicks(stage)
        Else
            MsgBox("Job is already finished")
        End If
    End Sub
    

    结束类别

    这个 imgList 通过拖放填充,如下所示:

     Public Sub pctadd_drop(sender As Object, e As DragEventArgs) Handles pctAdd.DragDrop
        Dim picStr() As String = CType(e.Data.GetData(DataFormats.FileDrop), String())
        Dim newList As List(Of String) = picStr.ToList
        For Each img In newList
            If Not imgList.Contains(img) Then
                imgList.Add(img)
            Else
                MsgBox("Image already present")
            End If
        Next
        pctAdd.ImageLocation = imgList(newList.Count - 1)
        udPics.Maximum = newList.Count
        udPics.Value = newList.Count
        udPics.Minimum = 1
        txtID.Text = Strings.Right(imgList(0).Remove(imgList(0).Length - 4, 4), 4)
    End Sub 
    

    如果我遗漏了什么,请告诉我,我自己也尝试过调试,但我真的看不出问题出在哪里!

    2 回复  |  直到 9 年前
        1
  •  1
  •   NoAlias    9 年前

    将imgList分配给initJob中作业的图像属性的方式是错误的。所有作业都将使用相同的imgList。

    将其更改为:

    Public Sub initJob(ID As String, notes As String, product As String, eta As Integer)
    
        Orders.JobsDict.Add(ID, New job)
        Orders.JobsDict(ID).ID = ID
        Orders.JobsDict(ID).notes = notes
        Orders.JobsDict(ID).product = product
        Orders.JobsDict(ID).stage = 0
        Orders.JobsDict(ID).images = New List(of String)
    
        For Each strImage in imgList
    
            Orders.JobsDict(ID).images.Add(strImage)
    
        Next
    
        Orders.JobsDict(ID).ETA = eta
        Orders.JobsDict(ID).bumped = False
        Orders.chkItemStage.SetItemChecked(0, True)
    
    End Sub
    

    编辑:

    为了更清楚地说明,当您将图像属性分配给传入的列表时,实际上是将其分配给imgList。最终,你有很多工作都共享相同的变量。通过将图像属性分配给它自己的唯一列表实例(字符串)并从imgList复制值,图像对于每个作业都是唯一的(假设imgList的值已更改)。

        2
  •  0
  •   CypherPotato    9 年前

    可爱的方法 PictubeBox.Update 将帮助您。

    Public Sub updatePics()
         udImage.Maximum = JobsDict(currentJob).images.Count
         udImage.Minimum = 1
         udImage.Value = 1
         pctJobPics.ImageLocation = JobsDict(currentJob).images(0)
         pctJobPics.Image = JobsDict(currentJob).images(0) 'if don't works, disable this
         Call pctJobPics.Update()
    End Sub