gpt4 book ai didi

.net - 消除 System.Array 中的间隙

转载 作者:行者123 更新时间:2023-12-04 00:43:06 25 4
gpt4 key购买 nike

我打算制作显示图片的应用程序。我想添加“删除”功能,但我遇到了问题。问题是图片之间的差距。我想删除它们。

例如:

我有这样的数组:
{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

最佳答案

我建议将您的图像存储在不同类型的集合中而不是数组中,例如 List(Of T),甚至是 LinkedList(Of T).

这些将允许您通过 List.Remove 直接从集合中删除图像等

关于.net - 消除 System.Array 中的间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16777597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com