我要制作显示图片的应用程序。我想添加“删除”功能,但我遇到了问题。问题是图片之间的差距。我想删除它们。
例如:
我有这样的数组:
{1 = image_1, 2 = image_2, 3 = image_3}
当我删除 image_2 我有:
{1 = image_1, 2 = nil, 3 = image_3}
我想:
{1 = image_1, 2 = Image_3}
代码:
Public Class Form1
Dim latestImageId As Integer = 0
Dim dispPictureId As Integer = 0
Dim images(128) As Image
Private Sub CapturePic(sender As Object, e As EventArgs) Handles TestToolStripMenuItem.Click
If My.Computer.Clipboard.ContainsImage() Then
latestImageId = (latestImageId + 1)
images(latestImageId) = My.Computer.Clipboard.GetImage()
If dispPictureId = 0 Then
Label1.Text = dispPictureId
dispPictureId = 1
PictureBox1.Image = images(dispPictureId)
End If
End If
Label1.Text = dispPictureId
End Sub
Private Sub Nex_Click(sender As Object, e As EventArgs) Handles Nex.Click
If Not images(dispPictureId + 1) Is Nothing Then
PictureBox1.Image = images(dispPictureId + 1)
Else
Exit Sub
End If
dispPictureId = (dispPictureId + 1) Mod images.Length
Label1.Text = dispPictureId
End Sub
Private Sub Pre_Click(sender As Object, e As EventArgs) Handles Pre.Click
If Not images(dispPictureId - 1) Is Nothing Then
PictureBox1.Image = images(dispPictureId - 1)
Else
Exit Sub
End If
dispPictureId = (dispPictureId - 1) Mod images.Length
Label1.Text = dispPictureId
End Sub
Private Sub Del_Click(sender As Object, e As EventArgs) Handles Del.Click
images(dispPictureId) = Nothing
If images(dispPictureId) Is Nothing Then
dispPictureId = dispPictureId - 1
End If
dispPictureId = 1
Label1.Text = dispPictureId
End Sub
End Class