【问题标题】:How to Pass A Image In ImageList Collection to PictureBox如何将 ImageList 集合中的图像传递给 PictureBox
【发布时间】:2014-08-26 10:38:55
【问题描述】:

为了提高我的技能,我正在为我的孩子们在 VB.Net 中开发一个小应用程序,以帮助他们拼写单词。抛开其他一切不谈,这是迄今为止的形式:

当用户单击“下一步”按钮时,我的 ImageList 集合中的 3 个图像将被推送到 PictureBox 控件,该控件将出现在表单的上部 - 我在运行时将其隐藏。但是,每次用户单击 Next 时,我只会在 PictureBox 中显示一个图像,而不是所有图像。这是我连接下一个按钮的点击事件的代码:

Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
    'Get images and place them in the Imagebox on each click.

    Dim count As Integer
    count += 1
    If count < ImageList1.Images.Count - 1 Then
        count = 0
    End If
    PictureBox1.Image = ImageList1.Images(count)
End Sub

我这辈子都无法在点击时显示其他图像。谁能为我提供解决方案并告诉我哪里出错了?最后,我想添加我预先录制的音频文件,当用户在显示图像时单击下一步时播放:

“拼出‘自行车’这个词!”

并且 PictureBox 包含一个自行车图像,等等。我非常感谢有关如何完成此任务的帮助。谢谢。

【问题讨论】:

    标签: vb.net picturebox imagelist


    【解决方案1】:

    Dim count As Integer 每次单击按钮时,count 为零,因为它是一个局部变量。声明它Static 即使在单击按钮后也会存储该值。这就像像Private count As Integer 一样在外面声明它,但只在按钮点击子内可见。

    Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
        'Get images and place them in the Imagebox on each click.
    
        Static count As Integer = 0
    
        If count > ImageList1.Images.Count - 1 Then
            count = 0
        End If
        PictureBox1.Image = ImageList1.Images(count)
    
        count += 1
    End Sub
    

    瓦尔特

    【讨论】:

    • 感谢一百万,瓦尔特!正是我需要的。另外,感谢您解释静态声明的使用......我的工具箱中没有的东西。我很感激!如果我想从集合中的图像开始,我会设置Static count As Integer = 1吗?
    • @DesignerMind 是的。你想要什么价值
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-22
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多