Question Delete button

dentfree

New member
Joined
Feb 28, 2012
Messages
3
Programming Experience
Beginner
I create many buttons in code like :
VB.NET:
    Public Sub GenereTextBox(ByVal rep As String)
        Dim txt As New TextBox
        Dim fnt As Font

        fnt = Me.Font
        txt.Location = New Drawing.Point(26 + NbreCacher * (68), txtOrdonnee)
        txt.Font = New Font(fnt.Name, 40, FontStyle.Regular)
        txt.Size = New Size(130, 37)
        txt.Multiline = True
        txt.Name = "textb" + Str((NbreEssai - 1) * 4)
        Me.Controls.Add(txt)
        txt.Text = rep
        txtOrdonnee = txtOrdonnee + 40
        txt.ReadOnly = True
    End Sub

And I want delete some buttons crete when I click on my button, but i don't how i can do, because these buttons are create in code??
 
I'm Not sure if you can actully delete a button but you can make it go invisible like so

VB.NET:
bntNamedButton.Visible = False ' Or True to which desired effect your after

Hope that helps :)


VB.NET:
did a bit of sniffing and found this

Control c = this.Controls.Find(yourButtonControl.Name, true)[0];
this.Controls.Remove(c)

Which i C++ but easily changed :)
 
I'll try your code in vb.net the next time I need to do this ProtekNickz ;) Much less work :)

I use normally use something like this, hope it helps :)



Public Sub RemoveTextBox(ByVal TextboxName As String)

For Each txtbox As TextBox In Controls
If txtbox.Name = TextboxName Then
Controls.Remove(txtbox)
Exit For
End If
Next

End Sub
Info: 'TextboxName = "textb" + Str((NbreEssai - 1) * 4)


Public Sub RemoveButton(ByVal ButtonName As String)

For Each btn As Button In Controls
If btn.Name = ButtonName Then
Controls.Remove(btn)
Exit For
End If
Next

End Sub
 
As you're giving the Buttons names, you can get them back by that name from the Controls collection you added them to. To destroy them, Remove them from the collection and call their Dispose method.
 
Back
Top