By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,822 Members | 729 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,822 IT Pros & Developers. It's quick & easy.

Need more efficient way to load/unload user controls on form

P: n/a
We have a Windows app that has one main form (a shell, sort of). We then
load user controls into a panel on the form depending on what the user has
selected.

Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to the
project, we have to add some code in the section where we are
loading/unloading.

Is there a more dynamic, more efficient way to manage user controls loading
in a form?

Any help would be appreciated.

Thanks,
Ron
Feb 14 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
I would use VB.

VB is obviously more efficient than CSharp

I mean; CSharp has only been around for a couple of years now; it's
basically still in beta

On Feb 13, 7:24 pm, "Ronald S. Cook" <r...@westinis.comwrote:
We have a Windows app that has one main form (a shell, sort of). We then
load user controls into a panel on the form depending on what the user has
selected.

Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to the
project, we have to add some code in the section where we are
loading/unloading.

Is there a more dynamic, more efficient way to manage user controls loading
in a form?

Any help would be appreciated.

Thanks,
Ron

Feb 14 '07 #2

P: n/a
That's not true.

Robin S.
-----------------------------------
<aa*********@gmail.comwrote in message
news:11**********************@p10g2000cwp.googlegr oups.com...
>I would use VB.

VB is obviously more efficient than CSharp

I mean; CSharp has only been around for a couple of years now; it's
basically still in beta

On Feb 13, 7:24 pm, "Ronald S. Cook" <r...@westinis.comwrote:
>We have a Windows app that has one main form (a shell, sort of). We
then
load user controls into a panel on the form depending on what the user
has
selected.

Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to
the
project, we have to add some code in the section where we are
loading/unloading.

Is there a more dynamic, more efficient way to manage user controls
loading
in a form?

Any help would be appreciated.

Thanks,
Ron


Feb 14 '07 #3

P: n/a
Hi Ronald,

There are different ways to do this. One way is to treat your user controls
as plugins. Example would be that all your controls implement an interface
which would have Load(...) and Unload(...) methods. Then you would have a
control container for each option which would contain the user controls for
that option. And finally when ever a user selects an option then the form
would call Controlcontainer's Display() method (Check the code below)

some pseudo-code:

public interface IControlPlugin
{
void Load(...);
void Unload(...);
}
public class MyControl : UserControl, IControlPlugin
{
...
public void Load(...)
{
...
}

public void Unload(...)
{
...
}
}
public class ControlContainer : UserControl
{
private List<UserControlmControls;

public void Add(UserControl control)
{
if(control is IControlPlugin)
mControls.Add(control);
else
throw new Exception("Interface not implemented");
}

public void DisplayControls(Control parent)
{
foreach(UserControl ctrl in mControls)
{
IControlPlugin plugin = ctrl as IControlPlugin;
ctrl.Load();
parent.Controls.Add(ctrl);
ctrl.Parent = this;
}
}

public void UnloadControls(Control parent)
{
foreach(UserControl ctrl in mControls)
{
IControlPlugin plugin = ctrl as IControlPlugin;
ctrl.Unload();
parent.Controls.Remove(ctrl);
ctrl.Parent = null;
ctrl.Dispose();
}
}
}
Hope this helps
Fitim Skenderi

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
We have a Windows app that has one main form (a shell, sort of). We then
load user controls into a panel on the form depending on what the user has
selected.

Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to the
project, we have to add some code in the section where we are
loading/unloading.

Is there a more dynamic, more efficient way to manage user controls
loading in a form?

Any help would be appreciated.

Thanks,
Ron


Feb 14 '07 #4

P: n/a
why is it not true?

C sharp is still in beta; I mean; it's only been around for a couple
of years

it's sort of like 'dont ever buy windows until sp1 comes out'

except csharp needs about FORTY FUCKING YEARS TO CATCH UP TO VB


On Feb 14, 12:31 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
That's not true.

Robin S.
-----------------------------------<aaron.ke...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
I would use VB.
VB is obviously more efficient than CSharp
I mean; CSharp has only been around for a couple of years now; it's
basically still in beta
On Feb 13, 7:24 pm, "Ronald S. Cook" <r...@westinis.comwrote:
We have a Windows app that has one main form (a shell, sort of). We
then
load user controls into a panel on the form depending on what the user
has
selected.
Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to
the
project, we have to add some code in the section where we are
loading/unloading.
Is there a more dynamic, more efficient way to manage user controls
loading
in a form?
Any help would be appreciated.
Thanks,
Ron- Hide quoted text -

- Show quoted text -

Feb 14 '07 #5

P: n/a
Thanks, I'll try that. Any other options?
"fitim skenderi" <fi****@hotmail.comwrote in message
news:O4**************@TK2MSFTNGP06.phx.gbl...
Hi Ronald,

There are different ways to do this. One way is to treat your user
controls as plugins. Example would be that all your controls implement an
interface which would have Load(...) and Unload(...) methods. Then you
would have a control container for each option which would contain the
user controls for that option. And finally when ever a user selects an
option then the form would call Controlcontainer's Display() method (Check
the code below)

some pseudo-code:

public interface IControlPlugin
{
void Load(...);
void Unload(...);
}
public class MyControl : UserControl, IControlPlugin
{
...
public void Load(...)
{
...
}

public void Unload(...)
{
...
}
}
public class ControlContainer : UserControl
{
private List<UserControlmControls;

public void Add(UserControl control)
{
if(control is IControlPlugin)
mControls.Add(control);
else
throw new Exception("Interface not implemented");
}

public void DisplayControls(Control parent)
{
foreach(UserControl ctrl in mControls)
{
IControlPlugin plugin = ctrl as IControlPlugin;
ctrl.Load();
parent.Controls.Add(ctrl);
ctrl.Parent = this;
}
}

public void UnloadControls(Control parent)
{
foreach(UserControl ctrl in mControls)
{
IControlPlugin plugin = ctrl as IControlPlugin;
ctrl.Unload();
parent.Controls.Remove(ctrl);
ctrl.Parent = null;
ctrl.Dispose();
}
}
}
Hope this helps
Fitim Skenderi

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
>We have a Windows app that has one main form (a shell, sort of). We then
load user controls into a panel on the form depending on what the user
has selected.

Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to
the project, we have to add some code in the section where we are
loading/unloading.

Is there a more dynamic, more efficient way to manage user controls
loading in a form?

Any help would be appreciated.

Thanks,
Ron



Feb 14 '07 #6

P: n/a
how is it not true?

c# was invented for no reason; because MS didn't understand or
appreciate the popularity of VB

that is the only reason
and now .NET is a 1/4 replacement for Vb6-- I can't use .NET in
ActiveX scripts; I can't use .NET in office or in VBS files


and I can't use vb.net or vbs on the clientside of a browser
IS THIS PROGRESS??
C@ On Feb 14, 12:31 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
That's not true.

Robin S.
-----------------------------------<aaron.ke...@gmail.comwrote in message

news:11**********************@p10g2000cwp.googlegr oups.com...
I would use VB.
VB is obviously more efficient thanCSharp
I mean;CSharphas only been around for a couple of years now; it's
basically still in beta
On Feb 13, 7:24 pm, "Ronald S. Cook" <r...@westinis.comwrote:
We have a Windows app that has one main form (a shell, sort of). We
then
load user controls into a panel on the form depending on what the user
has
selected.
Our current code to unload the existing user control and load the newly
selected one is pretty bulky. Every time we add a new user control to
the
project, we have to add some code in the section where we are
loading/unloading.
Is there a more dynamic, more efficient way to manage user controls
loading
in a form?
Any help would be appreciated.
Thanks,
Ron- Hide quoted text -

- Show quoted text -

Feb 16 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.