Remove buttons

G

Guest

here is the code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim start As Integer = 4
Dim top As Integer = 25
Dim i As Integer
Dim nowdate As DateTime = DateTime.Now
Dim mybutton(10) As Button
For i = 0 To 9
mybutton(i) = New Button
mybutton(i).TextAlign = ContentAlignment.MiddleCenter
mybutton(i).Width = 140
mybutton(i).Height = 120
mybutton(i).FlatStyle = FlatStyle.Flat
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Location = New System.Drawing.Point(start, top)
mybutton(i).Text = (i + 1).ToString
mybutton(i).Cursor = Cursors.Hand
Me.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
AddHandler mybutton(i).MouseHover, AddressOf mybutton_Hoover
AddHandler mybutton(i).MouseLeave, AddressOf mybutton_Leave
start = start + 140
If (i + 1) Mod 5 = 0 Then
top = top + 120
start = 4
End If
Next
End Sub

Q. how do i delete or remove buttons in this array (mybuttons(10)) using the click event of another button outside this array? say Button1_click

NEED THE CODE PLEASE

THANX IN ADVANCE
 
W

William Ryan

Me.Controls.Remove(Me.Button1)

Will said:
here is the code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim start As Integer = 4
Dim top As Integer = 25
Dim i As Integer
Dim nowdate As DateTime = DateTime.Now
Dim mybutton(10) As Button
For i = 0 To 9
mybutton(i) = New Button
mybutton(i).TextAlign = ContentAlignment.MiddleCenter
mybutton(i).Width = 140
mybutton(i).Height = 120
mybutton(i).FlatStyle = FlatStyle.Flat
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Location = New System.Drawing.Point(start, top)
mybutton(i).Text = (i + 1).ToString
mybutton(i).Cursor = Cursors.Hand
Me.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
AddHandler mybutton(i).MouseHover, AddressOf mybutton_Hoover
AddHandler mybutton(i).MouseLeave, AddressOf mybutton_Leave
start = start + 140
If (i + 1) Mod 5 = 0 Then
top = top + 120
start = 4
End If
Next
End Sub

Q. how do i delete or remove buttons in this array (mybuttons(10)) using
the click event of another button outside this array? say Button1_click
 
C

Cor

Hi Will,

I thought I have seen the basic of this code before

If you want to remove as you are asking with the extra button, you have to
make the declaration of the button global. (outside the sub)

Than you can say in your extra button
\\\
me.controls.mybutton(x).remove
///
And that x should be in this case also global of course and setted before

I hope this helps?

Cor


Will said:
here is the code:

Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim start As Integer = 4
Dim top As Integer = 25
Dim i As Integer
Dim nowdate As DateTime = DateTime.Now
Dim mybutton(10) As Button
For i = 0 To 9
mybutton(i) = New Button
mybutton(i).TextAlign = ContentAlignment.MiddleCenter
mybutton(i).Width = 140
mybutton(i).Height = 120
mybutton(i).FlatStyle = FlatStyle.Flat
mybutton(i).BackColor = Drawing.Color.AntiqueWhite
mybutton(i).Location = New System.Drawing.Point(start, top)
mybutton(i).Text = (i + 1).ToString
mybutton(i).Cursor = Cursors.Hand
Me.Controls.Add(mybutton(i))
AddHandler mybutton(i).Click, AddressOf mybutton_Click
AddHandler mybutton(i).MouseHover, AddressOf mybutton_Hoover
AddHandler mybutton(i).MouseLeave, AddressOf mybutton_Leave
start = start + 140
If (i + 1) Mod 5 = 0 Then
top = top + 120
start = 4
End If
Next
End Sub

Q. how do i delete or remove buttons in this array (mybuttons(10)) using
the click event of another button outside this array? say Button1_click
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top