How to prevent "internal" controls from being used externally?

P

Peter Rilling

Hi,

I am writing some composite controls for a mobile device. Starting off with
a usercontrol, I then embed child control on it which will then be consumed
by other. The child controls are also custom and intended only for use on
the usercontrol (meaning I never want the user to explicitly add the child
controls to any of their forms).

What are some of the ways that I can prevent the user from using it on their
forms? On specific thing that I am looking at is preventing it from
appearing in the toolbox, but in the .xmta file, the ToolboxItem element is
not supported in the schema, which is what I beleive the full framework uses
for this purpose.

Any suggestions?
 
C

Christopher Fairbairn

Hi,

Peter Rilling said:
I am writing some composite controls for a mobile device. Starting off
with
a usercontrol, I then embed child control on it which will then be
consumed
by other. The child controls are also custom and intended only for use on
the usercontrol (meaning I never want the user to explicitly add the child
controls to any of their forms).

If I understand your situation correctly you should be able to achieve this
by changing the visibility of the child control classes.

By default the child controls will have public visibility, if you change
this to internal, only code within the containing assembly would be able to
create instances of the child controls. This means projects which add a
reference to your custom controls assembly won't be able to see the child
controls.

If you open up the *.cs file for your child user control within Visual
Studio you should be able to change the line which reads something like the
following:

"public partial class MyUserControl : UserControl ......"

to read

"internal partial class MyUserControl : UserControl ....."

Hope this helps,
Christopher Fairbairn
 
P

Peter Rilling

I tried that but the controls still appear in the toolbox, but compilation
obviously fails. How can I make it not appear in the toolbox, or should the
visibility also take care of this?
 
D

dbgrick

The control will only appear in the toolbox of the compiling application. I
don't think you can add controls that are internal through the Visual Studios
gui.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top