嘿,我已经创建了一个字典,用于创建图片框。每个图片框都有一个编号,然后我要使用该编号删除该编号对应的访问记录。因此,我已使字典正常工作,但是如何获得与每个图片框相对应的数字?这是我的代码(所有内容都已定义,例如cardsdictionary作为字典):
numpy
import numpy as np
D, N, Q, P = 2, 5, 4, 3 # Reduced problem dimensions.
items = 1.0 * np.arange(D * N * Q).reshape((D, N, Q)) # Example data
ids = np.arange(0, N * P).reshape(N, P) % Q # Example ids
# How can these loops be avoided?
my_items = np.zeros((D, N, P))
for n in range(N):
for p in range(P):
my_items[:, n, p] = items[:, n, ids[n, p]]
# print('items', items)
# print('ids', ids)
# print('my_items', my_items)
这是我的图像处理器!
Public Sub bigpictureloader()
'Dim list As New List(Of String)(cardsdictionary.Keys)
Dim cardcount As Integer
cardcount = 0
counter += 1
cardcount = counter
'Dim cards As List(Of String) = New List(Of String)
cardsdictionary.Add(imageurltxt.Text, cardcount)
'Create a placeholder variable
Dim cardPictureBox As PictureBox
Dim pair As KeyValuePair(Of String, Integer)
'Loop through every selected card URL
For Each pair In cardsdictionary
'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
'Add the PictureBox to the Form
Me.Controls.Add(cardPictureBox)
'MsgBox(cardsdict.Values.ToString)
If imageurltxt.Text = "" Then
cardPictureBox = Nothing
Else
cardPictureBox.LoadAsync(pair.Key)
TableLayoutPanel1.Controls.Add(cardPictureBox, 0, 0)
End If
Next
End Sub
答案 0 :(得分:0)
您可以使用PictureBox的Tag
属性来存储ID。创建PictureBox时,将填充此属性。
在处理程序中,您可以执行以下操作:
Private Sub imagehandler(Sender As Object, e As EventArgs)
Dim myPictureBox As PictureBox = CType(sender, PictureBox)
'Now you can access myPictureBox.Tag and pass it into your delete function
Dim id As Integer = -1
If Int32.TryParse(myPictureBox.Tag, id) = True Then
testdelete(id)
End If
End Sub
Private Sub testdelete(id As Integer)
'THIS SAVES TO THE DEBUG ACCESS DATABASE!!!!!
Using conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = FULL YUGIOH ACCESS DATABASE.accdb;")
Using command As New OleDbCommand("Delete From cmon11 Where ID= @ID;", conn)
'pair.value is what I think will work, but doesn't currently
command.Parameters.Add("@ID", OleDbType.Integer).Value = id
conn.Open()
command.ExecuteNonQuery()
End Using
End Using
End Sub
答案 1 :(得分:0)
testdelete不知道您要删除哪个图像。使用迈克尔的建议,您想要:
command.Parameters.Add("@ID", OleDbType.Integer).Value = CInt(Me.Tag)
通过这种方式,您可以大幅度清理计数器和卡号的使用情况。