•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 403,519 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,780 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 245 | Replies: 2 | Solved
![]() |
•
•
Join Date: Jul 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hi I have been writing VB.Net for a few weeks,
it has been going well but I am now stuck.
I have multiple user controls on a form and I need a way to remove a selected one. I was hoping that something like this would do it
But this only works for Button1, I am guessing this is because each instance is not called. “UserControl” and “UserControl1”. I have added the user controls using code and was wondering if there is anything I could do at the point of adding them, to idenfy them for later on. (i.e give them a name I could use later on)
Sorry if this is a daft question, it’s all fairly new to me.
Many thanks in advance
it has been going well but I am now stuck.
I have multiple user controls on a form and I need a way to remove a selected one. I was hoping that something like this would do it
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.Controls.RemoveByKey("UserControl")
refresh_Form()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Controls.RemoveByKey("UserControl1")
refresh_Form()
End Sub
But this only works for Button1, I am guessing this is because each instance is not called. “UserControl” and “UserControl1”. I have added the user controls using code and was wondering if there is anything I could do at the point of adding them, to idenfy them for later on. (i.e give them a name I could use later on)
Sorry if this is a daft question, it’s all fairly new to me.
Many thanks in advance
•
•
Join Date: Dec 2002
Location: West Virginia
Posts: 375
Reputation:
Rep Power: 6
Solved Threads: 38
Try this:
If Me.Controls.Contains(UserControl1) Then
Me.Controls.Remove(UserControl1)
End If Last edited by waynespangler : Jul 7th, 2008 at 10:09 pm.
Wayne
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
•
•
Join Date: Jul 2008
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks for the reply,
This is what I ended up using.
Live and learn
This is what I ended up using.
Live and learn
Public Class Form1
Public Mycontrol As New UserControl
Public Mycontrol1 As New UserControl
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Add_controls()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Remove_controls(Me.Mycontrol)
End Sub
End Class
Module Module1
Sub Add_controls()
'add two user controls'
Form1.Mycontrol.Location = New Point(0, 0)
Form1.Controls.Add(Form1.Mycontrol)
Form1.Mycontrol1.Location = New Point(60, 60)
Form1.Controls.Add(Form1.Mycontrol1)
End Sub
Sub Remove_controls(ByVal _Countrol As Control)
'remove a control'
If Form1.Controls.Contains(_Countrol) Then
Form1.Controls.Remove(_Countrol)
End If
End Sub
End Module![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Need help removing the viruses in this laptop! (HijackThis log) (Windows NT / 2000 / XP / 2003)
- XPSPZ | How can I remove this? (Viruses, Spyware and other Nasties)
- help with removing Aurora virus---new victim (Viruses, Spyware and other Nasties)
- Highjack file Ie wont download (Viruses, Spyware and other Nasties)
- removing annoying pop up (Viruses, Spyware and other Nasties)
- Need Help for DNS Problem and 'about:blank' Problem ... (Viruses, Spyware and other Nasties)
- about:blank hijacked, solutions offered not working (Viruses, Spyware and other Nasties)
- Win Min error when shutting down windows 98 (Viruses, Spyware and other Nasties)
- Windows vs Linux (Linux Users Lounge)
Other Threads in the VB.NET Forum
- Previous Thread: HOW TO DEPLOY vb.net application with database(sqlserver)
- Next Thread: flow arrows


Linear Mode