Hello everyone,
I am having a picture box on my form named pb and I am adding buttons through runtime, however I need a process for removing all buttons that belong to the pb collection, but for each statement removes one less object-button. Any suggestions please??? Any help would me much appreciated. Thank you so much in advanced.
Public Class Form1
Dim Btn1 As New Button
Dim btn2 As New Button
Dim btn3 As New Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Btn1.SetBounds(100, 200, 76, 27)
Btn1.Name = "button1"
btn2.BackColor = Color.Aqua
btn2.SetBounds(50, 100, 76, 27)
btn2.Name = "button2"
btn3.BackColor = Color.Green
btn3.SetBounds(300, 100, 76, 27)
btn3.Name = "button3"
pb.Controls.Add(Btn1)
pb.Controls.Add(btn2)
pb.Controls.Add(btn3)
End Sub
Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Remove.Click
For Each obj As Button In Me.pb.Controls
pb.Controls.Remove(obj)
Next
End Sub
I am having a picture box on my form named pb and I am adding buttons through runtime, however I need a process for removing all buttons that belong to the pb collection, but for each statement removes one less object-button. Any suggestions please??? Any help would me much appreciated. Thank you so much in advanced.
Public Class Form1
Dim Btn1 As New Button
Dim btn2 As New Button
Dim btn3 As New Button
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Btn1.SetBounds(100, 200, 76, 27)
Btn1.Name = "button1"
btn2.BackColor = Color.Aqua
btn2.SetBounds(50, 100, 76, 27)
btn2.Name = "button2"
btn3.BackColor = Color.Green
btn3.SetBounds(300, 100, 76, 27)
btn3.Name = "button3"
pb.Controls.Add(Btn1)
pb.Controls.Add(btn2)
pb.Controls.Add(btn3)
End Sub
Private Sub Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Remove.Click
For Each obj As Button In Me.pb.Controls
pb.Controls.Remove(obj)
Next
End Sub