嘿,所以我试图对我的图片进行编码,以使它们全部存储一个唯一的整数,然后我将在其他地方使用该整数,但是现在我真的很努力地只为它们存储一个值。这是我创建图片的代码,我如何为每张图片分配一个数字,第一张图片包含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
答案 0 :(得分:0)
这个答案只是为了帮助您参考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,因此您无需费心转换。如果您需要更多说明,我可以回答您的问题。
玩得开心!