
como crear 40 picturebox y limpiar picturebox en tiempo deejecucion en vb.net
Publicado por ros anhu apellido (5 intervenciones) el 28/08/2021 23:11:05
como crear 40 imagenes en tiempo de ejecucion y poder limpiarlas en vb.net2019
* creamos un panel pn para alli ponerls img
declaramos pb a nivel de formulario para q pieda ser agarrados desde otro evento
Dim pb As PictureBox
Sub crear_picturesBox_()
For i As Integer = 0 To 40 - 1
'Dim pb As New PictureBox
pb = New PictureBox
pb.Size = New Size(50, 60)
'pb.Location = New Point(10, 10)''original
'pb.SetBounds(10 * i, 10 * i, 40, 50)
pb.BringToFront()
pb.Name = "Carta" & i.ToString
pb.Tag = i ''para poder identificarlo con tag
'Me.Controls.Add(pb) ''agregamos al frm
pn.Controls.Add(pb)
'pb.Image = My.Resources.b1
'pb.Image = My.Resources._20507187_10154875904033177_3442867215593708903_o
pb.Image = My.Resources.interogacion
pb.BorderStyle = BorderStyle.None
'pb.SizeMode = PictureBoxSizeMode.AutoSize
pb.SizeMode = PictureBoxSizeMode.StretchImage
pb.Cursor = Cursors.Hand
''inicimos las variables x y y
'x_ = 10 : y_ = 10 ''valores iniciales para el primer cuadro
'Select Case i
' 'Case 1 : pb.Location = New Point(10, 10)
' Case 1 : pb.Location = New Point(x_, y_)
' 'diferencia 56
' Case 2 'To 10
' 'pb.Location = New Point(66, 10)
' ' 50+10+6
' 'pb.Location = New Point(pb.Width + 16, 10)
' pb.Location = New Point(10 + (pb.Width * 1) + 6, 10)
' Case 3
' 'pb.Location = New Point(122, 10)
' ' 50+20+6
' 'pb.Location = New Point(pb.Width + 72, 10)
' pb.Location = New Point(10 + pb.Width * 2 + 12, 10)
' Case 4
' 'pb.Location = New Point(178, 10)
' ' 50+20+6
' 'pb.Location = New Point(pb.Width + 128, 10)
' pb.Location = New Point(10 + pb.Width * 3 + 18, 10)
' Case 5
' pb.Location = New Point(10 + pb.Width * 4 + 24, 10)
' ''Case 11 : pb.Location = New Point(10, 76)
' 'Case 12 To 20 : pb.Location = New Point(10, 76 * i)
' 'Case 11 : Exit Sub
'End Select
''solucionado
'Dim j As Integer
'Select Case i
' 'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
' Case 0 To 9 '
' ''pero para q funcione asi, debe de estar en indice cero y no en uno
' '' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
' pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
' Case 10 To 19 '
' j = i - 10 '' q reicicie desde cero el i
' 'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
' Case 20 To 29
' j = i - 20 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
' Case 30 To 39
' j = i - 30 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
'End Select
''solucionado..modelode casino de naipes en losicturebox
'Dim j As Integer
'Select Case i
' 'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
' Case 0 To 7 '
' ''pero para q funcione asi, debe de estar en indice cero y no en uno
' '' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
' pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
' Case 8 To 15 '
' j = i - 10 '' q reicicie desde cero el i
' 'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
' Case 16 To 23
' j = i - 20 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
' Case 24 To 31
' j = i - 30 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
'End Select
''solucion para crear40 picturebox de 8 columnas x5 de fila
Dim j As Integer
Select Case i
'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
Case 0 To 7 '
''pero para q funcione asi, debe de estar en indice cero y no en uno
'' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
Case 8 To 15 '
j = i - 8 '' q reicicie desde cero el i
'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
Case 16 To 23
j = i - 16 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
Case 24 To 31
j = i - 24 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
Case 32 To 39
j = i - 32 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 4 + 6 * 4)
End Select
'ListBox1.Items.Add(pb.Name)
AddHandler pb.MouseUp, AddressOf PictureBox1_MouseUp
AddHandler pb.MouseDown, AddressOf PictureBox1_MouseDown
AddHandler pb.MouseMove, AddressOf PictureBox1_MouseMove
Next
End Sub
Sub LimpiarPicturebox(p As Object)
For Each c In p.Controls
If TypeOf (c) Is GroupBox Then
LimpiarPicturebox(c)
ElseIf TypeOf (c) Is PictureBox Then
CType(c, PictureBox).Image = My.Resources.integorante_cuadro
CType(c, PictureBox).BorderStyle = BorderStyle.FixedSingle
End If
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pn.Size = New Size(466, 342)
Call crear_picturesBox_()
crear_picturesBox_pantilla()
'Call crear_chk()
Call crear_pic_en_tablaLayot_panel()
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
StartPoint = DirectCast(sender, PictureBox).PointToScreen(New Point(e.X, e.Y))
IsDragging = True
'PropertyGrid1.SelectedObject(pb)''sale error
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If IsDragging Then
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim EndPoint As Point = pb.PointToScreen(New Point(e.X, e.Y))
pb.Left += (EndPoint.X - StartPoint.X)
pb.Top += (EndPoint.Y - StartPoint.Y)
StartPoint = EndPoint
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
IsDragging = False
End Sub
Private Sub butNuevo_Click(sender As Object, e As EventArgs) Handles butNuevo.Click
Call ocultar()
'Call LimpiarPicturebox(pn)
End Sub
* creamos un panel pn para alli ponerls img
declaramos pb a nivel de formulario para q pieda ser agarrados desde otro evento
Dim pb As PictureBox
Sub crear_picturesBox_()
For i As Integer = 0 To 40 - 1
'Dim pb As New PictureBox
pb = New PictureBox
pb.Size = New Size(50, 60)
'pb.Location = New Point(10, 10)''original
'pb.SetBounds(10 * i, 10 * i, 40, 50)
pb.BringToFront()
pb.Name = "Carta" & i.ToString
pb.Tag = i ''para poder identificarlo con tag
'Me.Controls.Add(pb) ''agregamos al frm
pn.Controls.Add(pb)
'pb.Image = My.Resources.b1
'pb.Image = My.Resources._20507187_10154875904033177_3442867215593708903_o
pb.Image = My.Resources.interogacion
pb.BorderStyle = BorderStyle.None
'pb.SizeMode = PictureBoxSizeMode.AutoSize
pb.SizeMode = PictureBoxSizeMode.StretchImage
pb.Cursor = Cursors.Hand
''inicimos las variables x y y
'x_ = 10 : y_ = 10 ''valores iniciales para el primer cuadro
'Select Case i
' 'Case 1 : pb.Location = New Point(10, 10)
' Case 1 : pb.Location = New Point(x_, y_)
' 'diferencia 56
' Case 2 'To 10
' 'pb.Location = New Point(66, 10)
' ' 50+10+6
' 'pb.Location = New Point(pb.Width + 16, 10)
' pb.Location = New Point(10 + (pb.Width * 1) + 6, 10)
' Case 3
' 'pb.Location = New Point(122, 10)
' ' 50+20+6
' 'pb.Location = New Point(pb.Width + 72, 10)
' pb.Location = New Point(10 + pb.Width * 2 + 12, 10)
' Case 4
' 'pb.Location = New Point(178, 10)
' ' 50+20+6
' 'pb.Location = New Point(pb.Width + 128, 10)
' pb.Location = New Point(10 + pb.Width * 3 + 18, 10)
' Case 5
' pb.Location = New Point(10 + pb.Width * 4 + 24, 10)
' ''Case 11 : pb.Location = New Point(10, 76)
' 'Case 12 To 20 : pb.Location = New Point(10, 76 * i)
' 'Case 11 : Exit Sub
'End Select
''solucionado
'Dim j As Integer
'Select Case i
' 'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
' Case 0 To 9 '
' ''pero para q funcione asi, debe de estar en indice cero y no en uno
' '' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
' pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
' Case 10 To 19 '
' j = i - 10 '' q reicicie desde cero el i
' 'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
' Case 20 To 29
' j = i - 20 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
' Case 30 To 39
' j = i - 30 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
'End Select
''solucionado..modelode casino de naipes en losicturebox
'Dim j As Integer
'Select Case i
' 'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
' Case 0 To 7 '
' ''pero para q funcione asi, debe de estar en indice cero y no en uno
' '' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
' pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
' Case 8 To 15 '
' j = i - 10 '' q reicicie desde cero el i
' 'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
' Case 16 To 23
' j = i - 20 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
' Case 24 To 31
' j = i - 30 '' q reicicie desde cero
' pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
'End Select
''solucion para crear40 picturebox de 8 columnas x5 de fila
Dim j As Integer
Select Case i
'Case 0 : pb.Location = New Point(10, 10)''inicia en 10,10
Case 0 To 7 '
''pero para q funcione asi, debe de estar en indice cero y no en uno
'' 10 q es fijo + 50 ancho pb * i q es del (0 to 9); 10 de top
pb.Location = New Point(10 + (pb.Width * i) + 6 * i, 10) ''la primera fila
Case 8 To 15 '
j = i - 8 '' q reicicie desde cero el i
'pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + 60 + 6)
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height + 6)
Case 16 To 23
j = i - 16 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 2 + 6 * 2)
Case 24 To 31
j = i - 24 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 3 + 6 * 3)
Case 32 To 39
j = i - 32 '' q reicicie desde cero
pb.Location = New Point(10 + (pb.Width * j) + 6 * j, 10 + pb.Height * 4 + 6 * 4)
End Select
'ListBox1.Items.Add(pb.Name)
AddHandler pb.MouseUp, AddressOf PictureBox1_MouseUp
AddHandler pb.MouseDown, AddressOf PictureBox1_MouseDown
AddHandler pb.MouseMove, AddressOf PictureBox1_MouseMove
Next
End Sub
Sub LimpiarPicturebox(p As Object)
For Each c In p.Controls
If TypeOf (c) Is GroupBox Then
LimpiarPicturebox(c)
ElseIf TypeOf (c) Is PictureBox Then
CType(c, PictureBox).Image = My.Resources.integorante_cuadro
CType(c, PictureBox).BorderStyle = BorderStyle.FixedSingle
End If
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
pn.Size = New Size(466, 342)
Call crear_picturesBox_()
crear_picturesBox_pantilla()
'Call crear_chk()
Call crear_pic_en_tablaLayot_panel()
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
StartPoint = DirectCast(sender, PictureBox).PointToScreen(New Point(e.X, e.Y))
IsDragging = True
'PropertyGrid1.SelectedObject(pb)''sale error
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
If IsDragging Then
Dim pb As PictureBox = DirectCast(sender, PictureBox)
Dim EndPoint As Point = pb.PointToScreen(New Point(e.X, e.Y))
pb.Left += (EndPoint.X - StartPoint.X)
pb.Top += (EndPoint.Y - StartPoint.Y)
StartPoint = EndPoint
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
IsDragging = False
End Sub
Private Sub butNuevo_Click(sender As Object, e As EventArgs) Handles butNuevo.Click
Call ocultar()
'Call LimpiarPicturebox(pn)
End Sub
Valora esta pregunta


0