我目前正在写一份有关营养的调查报告。一页用户可以使用箭头键在食物的份量之间进行切换。每个项目有49张图像。当前,如果按住箭头键,它会暂停,并且一旦松开,它只会切换到图像。我希望它能显示它经过的每个图像,而不是跳过每个图像。
我尝试使用while循环和if子句代替select情况,但是只是冻结了程序,如果遇到了同样的问题
这是用于在图像之间切换和检测按键的类
Public Class Carousel
Public Shared Function Slideshow(picturebox As Object, food As String, key As Object, file As Object)
Dim fullPath As String = IO.Path.GetFullPath(My.Resources.ResourceManager.BaseName)
fullPath = fullPath.Replace("\bin\Debug\Study_1b.Resources", "")
Dim bHandled As Boolean
Select Case key
Case Keys.Right
If file.count < 49 Then
file.count += 1
picturebox.Image = Image.FromFile(fullPath & $"\Resources\{food}_{file.count}.jpg")
bHandled = True
End If
Case Keys.Left
Console.WriteLine(file.count)
While file.count > 0
file.count -= 1
picturebox.Image = Image.FromFile(fullPath & $"\Resources\{food}_{file.count}.jpg")
bHandled = True
End While
End Select
End Function
End Class
这是其加载和调用位置的一部分
Private Sub ES1Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True
count = Random.rndCount()
fullPath = fullPath.Replace("\bin\Debug\Study_1b.Resources", "")
pbes21.Image = Image.FromFile(fullPath & $"\Resources\Por_{count}.jpg")
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
Carousel.slideshow(pbes21, "Por", keyData, Me)
End Function