removing controls [modified]
-
Hi, I need to remove all buttons on my form. I use now
For n As Integer = Controls.Count - 1 To 0 Step -1 Dim c As Control = Controls(n) If TypeOf c Is Button Then Me.Controls.Remove(c) End If Next
but when I use 0 to controls.count or a for each The routine do not remove all the buttons So the question is what is the best way to remove all buttons on a form? not all the controls on the form are buttons the OK and cancel are on a TableLayoutPanel these 2 has to stay Thanks
modified on Tuesday, May 12, 2009 6:32 AM
-
Hi, I need to remove all buttons on my form. I use now
For n As Integer = Controls.Count - 1 To 0 Step -1 Dim c As Control = Controls(n) If TypeOf c Is Button Then Me.Controls.Remove(c) End If Next
but when I use 0 to controls.count or a for each The routine do not remove all the buttons So the question is what is the best way to remove all buttons on a form? not all the controls on the form are buttons the OK and cancel are on a TableLayoutPanel these 2 has to stay Thanks
modified on Tuesday, May 12, 2009 6:32 AM
jan212r wrote:
TableLayoutPanel
There is your problem
jan212r wrote:
Controls.Count
controls will only return the controls directly on the form You'll have to use recursion and check if the current control is a parent control (groupbox / panel / tablelayoutpanel / ... ) if so call the same function and go over all the controls in that parent control
-
Hi, I need to remove all buttons on my form. I use now
For n As Integer = Controls.Count - 1 To 0 Step -1 Dim c As Control = Controls(n) If TypeOf c Is Button Then Me.Controls.Remove(c) End If Next
but when I use 0 to controls.count or a for each The routine do not remove all the buttons So the question is what is the best way to remove all buttons on a form? not all the controls on the form are buttons the OK and cancel are on a TableLayoutPanel these 2 has to stay Thanks
modified on Tuesday, May 12, 2009 6:32 AM
For Each Btn As Button In Me.Controls
Btn.Dispose()
NextThis removes all buttons directly on the form, And:
For Each pan As Panel In Me.Controls
For Each pButton as Button in pan.Controls
pButton.Dispose()
Next
NextRemoves all buttons in the panels contained by the form. Etc.. I think you'll get the trick :-\ Cheers, :cool: Zaegra
Motivation is the key to software development.
-
For Each Btn As Button In Me.Controls
Btn.Dispose()
NextThis removes all buttons directly on the form, And:
For Each pan As Panel In Me.Controls
For Each pButton as Button in pan.Controls
pButton.Dispose()
Next
NextRemoves all buttons in the panels contained by the form. Etc.. I think you'll get the trick :-\ Cheers, :cool: Zaegra
Motivation is the key to software development.
-
Thanks for the input. But this gives no awnser to the question. I have an option that works, but when I use for each it do not work. It remove about 25% of the buttons.
I think you haven't understood it properly: That is because those buttons are NOT directly on the form, so you'll have to iterate through each container that might contain a button and then remove it. It's as simple as that ;) Cheers, Zaegra
Motivation is the key to software development.
-
I think you haven't understood it properly: That is because those buttons are NOT directly on the form, so you'll have to iterate through each container that might contain a button and then remove it. It's as simple as that ;) Cheers, Zaegra
Motivation is the key to software development.
Thats also the reasen why the are on a other control becourse these 2 must stay on the form, but the others 1-60 depending on the status must all been removed. But when there are 12 (+ ok and cancel) on the form there are only 3 buttons that are removed so there stay 9 + ok + cancel Jan
-
Thats also the reasen why the are on a other control becourse these 2 must stay on the form, but the others 1-60 depending on the status must all been removed. But when there are 12 (+ ok and cancel) on the form there are only 3 buttons that are removed so there stay 9 + ok + cancel Jan
i am trying to remove a DomainUpDown control at runtime. My coding is as follows and it gives error. Dim UpDown As System.Windows.Forms.DomainUpDown For Each UpDown In Me.Controls UpDown.Dispose() Next What is the error and how do I correct it. Someone please help.