Home All Groups Group Topic Archive Search About

About Adding controls dynamically

Author
7 Aug 2006 8:57 AM
crazyjh
hello

i want to add some controls in according of the time.
but when the time change, i call the method again to add controls again,No
effect!
i think maybe i should unload the controls adding before,how can i unload
it??

pls help me,thanks

Author
7 Aug 2006 9:09 AM
Cor Ligthert [MVP]
Crazyjh,

For using dynamic controls it is important to know if it is about a webpage
or a winform. They act completely different in this, so let us know that to
make the answers not only confusing.

Cor

Show quoteHide quote
"crazyjh" <craz***@gmail.com> schreef in bericht
news:eU5Mz9fuGHA.736@TK2MSFTNGP02.phx.gbl...
> hello
>
> i want to add some controls in according of the time.
> but when the time change, i call the method again to add controls again,No
> effect!
> i think maybe i should unload the controls adding before,how can i unload
> it??
>
> pls help me,thanks
>
Author
7 Aug 2006 9:16 AM
crazyjh
thanks for your reply

the development based on vb.net2005 + winform




----- Original Message -----
From: "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl>
Newsgroups: microsoft.public.dotnet.languages.vb
Sent: Monday, August 07, 2006 6:09 PM
Subject: Re: About Adding controls dynamically


Show quoteHide quote
| Crazyjh,
|
| For using dynamic controls it is important to know if it is about a
webpage
| or a winform. They act completely different in this, so let us know that
to
| make the answers not only confusing.
|
| Cor
|
Author
7 Aug 2006 10:07 AM
Cor Ligthert [MVP]
Crazyjh,

The oposite from adding a control is the control.remove
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.remove.aspx

I hope this helps,

Cor


Show quoteHide quote
"crazyjh" <craz***@gmail.com> schreef in bericht
news:OkdCqIguGHA.4612@TK2MSFTNGP02.phx.gbl...
> thanks for your reply
>
> the development based on vb.net2005 + winform
>
>
>
>
> ----- Original Message -----
> From: "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl>
> Newsgroups: microsoft.public.dotnet.languages.vb
> Sent: Monday, August 07, 2006 6:09 PM
> Subject: Re: About Adding controls dynamically
>
>
> | Crazyjh,
> |
> | For using dynamic controls it is important to know if it is about a
> webpage
> | or a winform. They act completely different in this, so let us know that
> to
> | make the answers not only confusing.
> |
> | Cor
> |
>
Author
7 Aug 2006 10:20 AM
crazyjh
thanks

i used the sentences below,it appearly doesn't work! lbl is dynamic added in
a function a,next time when i called a,the "if" statement don't work at all

dim lbl(i) as label
lbl(i) = new label
    If (me.Contains(lbl(i))) Then
                    me.Controls.Remove(lbl(i))
    End If

"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23jXzVkguGHA.1296@TK2MSFTNGP02.phx.gbl...
| Crazyjh,
|
| The oposite from adding a control is the control.remove
|
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.remove.aspx
Show quoteHide quote
|
| I hope this helps,
|
| Cor
|
Author
7 Aug 2006 11:08 AM
Cor Ligthert [MVP]
crazyjh,

You have to remove the original added control. This lbl(i) is a complete new
label that is never in your control collection as long as you don't add it.

You can as well use the removeAt.
http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.removeat.aspx

Be aware that this reindexes the index.

Cor

Show quoteHide quote
"crazyjh" <craz***@gmail.com> schreef in bericht
news:%23j0tOsguGHA.1296@TK2MSFTNGP02.phx.gbl...
> thanks
>
> i used the sentences below,it appearly doesn't work! lbl is dynamic added
> in
> a function a,next time when i called a,the "if" statement don't work at
> all
>
> dim lbl(i) as label
> lbl(i) = new label
>    If (me.Contains(lbl(i))) Then
>                    me.Controls.Remove(lbl(i))
>    End If
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%23jXzVkguGHA.1296@TK2MSFTNGP02.phx.gbl...
> | Crazyjh,
> |
> | The oposite from adding a control is the control.remove
> |
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.controlcollection.remove.aspx
> |
> | I hope this helps,
> |
> | Cor
> |
>
Author
7 Aug 2006 10:10 AM
Herfried K. Wagner [MVP]
"crazyjh" <craz***@gmail.com> schrieb:
> i want to add some controls in according of the time.
> but when the time change, i call the method again to add controls again,No
> effect!
> i think maybe i should unload the controls adding before,how can i unload
> it??

You can remove the control from the container's (form, control) 'Controls'
collection.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>