嘿所以我正在尝试对我的图片进行编码,以便所有这些图片都存储一个唯一的整数,我将在其他地方使用它,但我现在真的很难为它们存储一个值。这是我创建图片的代码,如何为每张图片指定一个数字,第一张图片包含1,第二张图片包含1 ...所以要测试例如当我点击图片时,会显示他们的编号。
Private Sub bigpictureloader()
Dim cardcount As Integer
Dim cards As List(Of String) = New List(Of String)
cards.Add(imageurltxt.Text)
'Create a placeholder variable
Dim cardPictureBox As PictureBox
'Loop through every selected card URL
For Each url As String In cards
'Create a new PictureBox
cardPictureBox = New PictureBox()
cardPictureBox.Size = New Size(100, 100)
cardPictureBox.SizeMode = PictureBoxSizeMode.Zoom
cardPictureBox.WaitOnLoad = False
AddHandler cardPictureBox.Click, AddressOf imagehandler
cardcount = 0
count += 1
cardcount = count
cardPictureBox.Tag = cardcount.ToString
MsgBox(cardPictureBox.Tag)
'Add the PictureBox to the Form
Me.Controls.Add(cardPictureBox)
If imageurltxt.Text = "" Then
cardPictureBox = Nothing
Else
cardPictureBox.LoadAsync(url)
TableLayoutPanel1.Controls.Add(cardPictureBox, 0, 0)
cardcount = 0
' this is what I tried but I can't get the image to store the cardcount
count += 1
cardcount = count
MsgBox(cardcount)
End If
'Load the image asynchronously
' cardPictureBox.LoadAsync(url)
'TableLayoutPanel1.Controls.Add(cardPictureBox, 0, 0)
Next
End Sub
这是点击图片的事件的代码,我如何转移卡片数量?
'Can't seem to transfer the cardcount to here
' tried cardpicturebox instead of sender but it still doesn't transfer cardcount
Private Sub imagehandler(Sender As Object, e As EventArgs)
bigpictureloader()
testdelete()
End Sub
这个答案只是为了帮助你了解jmcihinney的评论。如果它有帮助,请提出他的意见,因为它们是合理的建议。
这是一个代码片段,它创建一个继承自PictureBox类的自定义类。简而言之,它是一个带有一些附加功能的PictureBox:
Class Cards
Inherits PictureBox
'This holds the 'Card number' value
Private _number As Integer
'This makes the CardNumber Property Public. You can access it from outside, and in the designer
Public Property CardNumber As Integer
Get
Return _number
End Get
Set(value As Integer)
_number = value
End Set
End Property
'This is a fake function just to show that you could add custom functions here
Public Sub FakeSub()
MessageBox.Show("My card number is: " & _number.ToString)
End Sub
End Class
使用这个类而不是PictureBox,你将能够从课外访问你设置的属性(我编写了一个看起来有点像你想要的属性,但我会把细节留给你)(因为它是上市)。如果您在设计器中创建一个,您会注意到您的公共属性显示其他属性!这不是很棒吗?
此外,此属性被声明为Integer,您不必为转换而烦恼。如果您需要更多解释,我可以回答您的问题。
玩得开心!