Home All Groups Group Topic Archive Search About

Remove not hide User Control, posting again

Author
24 Mar 2006 9:26 AM
Mike TI
March 24, 2006

Hi all

I am new to VB.NET and am using VB.NET 2005.

I have an MDI form with a Split Container Control. On demand I am adding and
removing User Controls on Panel 2. I am using Show() and Hide(). It works
perfectly. The only thing is I would like to remove the User Control from
memory instead of hiding. I tried Dispose(), however then I cannot show this
user control again.

UserControl.Parent=Form.SplitContainer1.Panel2
UserControl.Dock=DockStyle.Fill
UserControl.Show()
..
..
UserControl.Hide()

Thanks.

Author
24 Mar 2006 9:45 AM
Armin Zingler
"Mike TI" <sunset***@hotmail.com> schrieb
> March 24, 2006
>
> Hi all
>
> I am new to VB.NET and am using VB.NET 2005.
>
> I have an MDI form with a Split Container Control. On demand I am
> adding and removing User Controls on Panel 2. I am using Show() and
> Hide(). It works perfectly. The only thing is I would like to remove
> the User Control from memory instead of hiding. I tried Dispose(),
> however then I cannot show this user control again.

This is a contradiction: Remove from memory .... show again.

If you removed something from memory, you can not show it again because it
does not exist anymore.

> UserControl.Parent=Form.SplitContainer1.Panel2
> UserControl.Dock=DockStyle.Fill
> UserControl.Show()
> .
> .
> UserControl.Hide()
>
> Thanks.


Armin
Author
24 Mar 2006 10:07 AM
Mike TI
I mean is it possible for me to show the user control again and again on
demand with the same behaviour as it was displayed for first time (firing
load event etc.) instead of using Hide() which probably is the same thing as
Visible=False.

Thank you.

Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:ePo5jiyTGHA.4492@TK2MSFTNGP09.phx.gbl...
> "Mike TI" <sunset***@hotmail.com> schrieb
>> March 24, 2006
>>
>> Hi all
>>
>> I am new to VB.NET and am using VB.NET 2005.
>>
>> I have an MDI form with a Split Container Control. On demand I am
>> adding and removing User Controls on Panel 2. I am using Show() and
>> Hide(). It works perfectly. The only thing is I would like to remove
>> the User Control from memory instead of hiding. I tried Dispose(),
>> however then I cannot show this user control again.
>
> This is a contradiction: Remove from memory .... show again.
>
> If you removed something from memory, you can not show it again because it
> does not exist anymore.
>
>> UserControl.Parent=Form.SplitContainer1.Panel2
>> UserControl.Dock=DockStyle.Fill
>> UserControl.Show()
>> .
>> .
>> UserControl.Hide()
>>
>> Thanks.
>
>
> Armin
Author
24 Mar 2006 10:14 AM
Stephany Young
Of course you can. That's the whole rationale behind instantiating objects.

Just create an new instance of the component, set all the relevant
properties as required and hook up the event handlers as required and Bob's
your uncle.


Show quoteHide quote
"Mike TI" <sunset***@hotmail.com> wrote in message
news:%23xIiUryTGHA.1868@TK2MSFTNGP09.phx.gbl...
>I mean is it possible for me to show the user control again and again on
>demand with the same behaviour as it was displayed for first time (firing
>load event etc.) instead of using Hide() which probably is the same thing
>as Visible=False.
>
> Thank you.
>
> "Armin Zingler" <az.nospam@freenet.de> wrote in message
> news:ePo5jiyTGHA.4492@TK2MSFTNGP09.phx.gbl...
>> "Mike TI" <sunset***@hotmail.com> schrieb
>>> March 24, 2006
>>>
>>> Hi all
>>>
>>> I am new to VB.NET and am using VB.NET 2005.
>>>
>>> I have an MDI form with a Split Container Control. On demand I am
>>> adding and removing User Controls on Panel 2. I am using Show() and
>>> Hide(). It works perfectly. The only thing is I would like to remove
>>> the User Control from memory instead of hiding. I tried Dispose(),
>>> however then I cannot show this user control again.
>>
>> This is a contradiction: Remove from memory .... show again.
>>
>> If you removed something from memory, you can not show it again because
>> it does not exist anymore.
>>
>>> UserControl.Parent=Form.SplitContainer1.Panel2
>>> UserControl.Dock=DockStyle.Fill
>>> UserControl.Show()
>>> .
>>> .
>>> UserControl.Hide()
>>>
>>> Thanks.
>>
>>
>> Armin
>
>
Author
24 Mar 2006 10:14 AM
Cor Ligthert [MVP]
Mike,

Of course you only have to instance it from its class and add it to your
form again.

Dim myControl as New myUsercontrol.
me.controls.add(myControl)

And set than the right properties again.

I hope this helps,

Cor

Show quoteHide quote
"Mike TI" <sunset***@hotmail.com> schreef in bericht
news:%23xIiUryTGHA.1868@TK2MSFTNGP09.phx.gbl...
>I mean is it possible for me to show the user control again and again on
>demand with the same behaviour as it was displayed for first time (firing
>load event etc.) instead of using Hide() which probably is the same thing
>as Visible=False.
>
> Thank you.
>
> "Armin Zingler" <az.nospam@freenet.de> wrote in message
> news:ePo5jiyTGHA.4492@TK2MSFTNGP09.phx.gbl...
>> "Mike TI" <sunset***@hotmail.com> schrieb
>>> March 24, 2006
>>>
>>> Hi all
>>>
>>> I am new to VB.NET and am using VB.NET 2005.
>>>
>>> I have an MDI form with a Split Container Control. On demand I am
>>> adding and removing User Controls on Panel 2. I am using Show() and
>>> Hide(). It works perfectly. The only thing is I would like to remove
>>> the User Control from memory instead of hiding. I tried Dispose(),
>>> however then I cannot show this user control again.
>>
>> This is a contradiction: Remove from memory .... show again.
>>
>> If you removed something from memory, you can not show it again because
>> it does not exist anymore.
>>
>>> UserControl.Parent=Form.SplitContainer1.Panel2
>>> UserControl.Dock=DockStyle.Fill
>>> UserControl.Show()
>>> .
>>> .
>>> UserControl.Hide()
>>>
>>> Thanks.
>>
>>
>> Armin
>
>
Author
24 Mar 2006 10:18 AM
Armin Zingler
"Mike TI" <sunset***@hotmail.com> schrieb
> I mean is it possible for me to show the user control again and
> again on demand with the same behaviour as it was displayed for
> first time (firing load event etc.) instead of using Hide() which
> probably is the same thing as Visible=False.



If you do not want to use Hide, you have to remove it from the container
control, call Dispose and remove remaining references. Whenever you need a
control again, you can create it, set it's properites and add it to the
container (TheContainer.Controls.Add). If you have a variable declared using
"WithEvents" that was previously pointing to the former control, you can
assign the new control to this variable again and all event procedures will
be working just like with the former control. If you don't have a WithEvents
variable, use the AddHandler statement to attach event handlers to the new
control.


Armin