470,591 Members | 2,005 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,591 developers. It's quick & easy.

Calling a User Control

If I create a new and separate User Control, in the same way as I
would create a new Form with the IDE, and call it from the main form,
like so:

UserControl1 usc = new UserControl1();
usc.Show();

nothing happens. What is it, that I should do instead?
--
Thanks
Patrick De Ridder.
Nov 15 '05 #1
5 1157
AFAIK, a control must be placed onto, or assigned to, a form in order to be
displayed. (I believe this is what Michael Culley was saying.) The Show()
/ Hide() methods merely make the control visible or not on the form.

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message
news:ey**************@TK2MSFTNGP12.phx.gbl...
I think this should do it.

this.controls.add (usc);

--
Michael Culley
"Patrick De Ridder" <00*@000.com> wrote in message

news:if********************************@4ax.com...
If I create a new and separate User Control, in the same way as I
would create a new Form with the IDE, and call it from the main form,
like so:

UserControl1 usc = new UserControl1();
usc.Show();

nothing happens. What is it, that I should do instead?
--
Thanks
Patrick De Ridder.


Nov 15 '05 #2
On Fri, 29 Aug 2003 02:23:16 -0500, "Michael Mayer" <mi**@mag37.com>
wrote:
AFAIK, a control must be placed onto, or assigned to, a form in order to be
displayed. (I believe this is what Michael Culley was saying.) The Show()
/ Hide() methods merely make the control visible or not on the form.


Thanks,

Do I understand correctly that you are saying that a Control can only
be placed on an existing Form? (I.e., you have the Form in the
Designer and you drag a Control onto it).

My question then is: What then, is the function for, in the IDE, that
enables you to create a stand-alone Control, if a Control cannot live
a separate life?

--
Greetings,
pa***************@hetnet.nl
Nov 15 '05 #3
"Patrick De Ridder" <00*@000.com> wrote in message
news:d0********************************@4ax.com...
Do I understand correctly that you are saying that a Control can only
be placed on an existing Form? (I.e., you have the Form in the
Designer and you drag a Control onto it).
That's what I'm saying. I've only written a few controls, and am not an
expert on them, but my understanding is that a control's purpose in life is
to be added to a form (windows and/or web).

ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsforms.htm

Note that you don't strictly _have_ to drag a control onto a form. Code
such as Michael Culley showed should work too:
this.controls.add (usc);
or perhaps more like this:
Form aForm = new Form();
aForm.Controls.Add(new MyControl());
My question then is: What then, is the function for, in the IDE, that
enables you to create a stand-alone Control, if a Control cannot live
a separate life?


I'm not entirely sure what you mean by stand-alone control. Do you mean a
"User Control"? Those are generally used for grouping other controls into
one unit that you can re-use. For instance, you may want a control with a
label, a textbox, and a button that you can use again and again on forms to
provide that combined functionality of the three other controls, without
having to explictly place each of the three. There are many other, much
more powerful uses.

If you've made a control you want to show by itself, you could probably put
it on a form with no title bar, no border, and make the control fill the
entire area.

Hope that helps clear up some issues. I may be wrong on some of this, as
this is only my understanding. I haven't been able to find anything in the
documentation to support this (only hints such as the above ms-help link).
--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com

Nov 15 '05 #4
On Fri, 29 Aug 2003 17:46:52 -0500, "Michael Mayer" <mi**@mag37.com>
wrote:

If you've made a control you want to show by itself, you could probably put
it on a form with no title bar, no border, and make the control fill the
entire area.


Thanks. Yes I have already done that for a project that is completed
now. Before I received help from this ng on how to do boarderless
Forms, someone suggested using "stand-alone" User Controls, hence a
further question, for me to understand how "stand-alone" User Controls
should be used.

--
Regards,
Patrick.
Nov 15 '05 #5
On Sat, 30 Aug 2003 07:14:27 +0200, Patrick De Ridder
<pa***************@hetnet.nl> wrote:
. . . someone suggested using "stand-alone" User Controls, hence a
further question, for me to understand how "stand-alone" User Controls
should be used.


I have found sufficient information in MSDN.

--
Regards,
Patrick.
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Danny Ni | last post: by
5 posts views Thread by Simon Harris | last post: by
6 posts views Thread by evandelagrammaticas | last post: by
2 posts views Thread by planetthoughtful | last post: by
2 posts views Thread by John Wright | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.