473,383 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Adding an 'internal' control to the toolbox.

I frequently define internal UserControl-derived classes in my WinForms
apps:

internal class MyUserControl:UserControl{
...
}

I'll often need to embed these controls in a Form, whose class is
contained in the same assembly as the control. As far as I know, the only
way to do this using the designer is to add the UserControl-derived object
to the toolbox and then drag it from the toolbox to the target form.

To accomplish this, I use the toolbox's Add/Remove Items functionality.
When adding new UserControl(s) to the toolbox, the user is asked to choose
an assembly containing the UserControl. I browse for and choose the assembly
that I'm currently working on, call it /debug/MyAssembly.dll. The problem is
that the toolbox is only prepared to accept UserControl items that are
declared as "public," not those declared as "internal." For a variety of
reasons, I'd much prefer to have UserControls declared as internal if I'm
not exposing them to the outside world.

The only workaround is to temporarily change the scope of the
UserControl to public, recompile, Add the item to the toolbox, change the
modifier back to internal, and recompile again. I then have access to the
control from my toolbox. This clearly an ugly workaround. Do you know of an
easier way to add internal controls to the toolbox?

Thanks...
Nov 16 '05 #1
2 6773
If you are marking the controls as internal, then surely they can only be
instanciated from within that assembly .dll.

I am also hazarding a guess that the control you have added to the toolbox
will be using a cached copy of the referenced dll so that just because you
have recompiled the original as internal will not effect the toolbox
version.

See this from the C# Programmer's Reference...
The internal keyword is an access modifier for types and type members.
Internal members are accessible only within files in the same assembly. For
more information on assemblies, see Components and Assemblies.
A common use of internal access is in component-based development because it
enables a group of components to cooperate in a private manner without being
exposed to the rest of the application code. For example, a framework for
building graphical user interfaces could provide Control and Form classes
that cooperate using members with internal access. Since these members are
internal, they are not exposed to code that is using the framework.

It is an error to reference a member with internal access outside the
assembly within which it was defined.

Caution An internal virtual method can be overridden in some languages,
such as textual Microsoft intermediate language (MSIL) using Ilasm.exe, even
though it cannot be overridden using C#.
For a comparison of internal with the other access modifiers, see
Accessibility Levels.

Example
This example contains two files, Assembly1.cs and Assembly2.cs. The first
file contains an internal base class, BaseClass. In the second file, an
attempt to access the member of the base class will produce an error.

File Assembly1.cs:

// Assembly1.cs
// compile with: /target:library
internal class BaseClass
{
public static int IntM = 0;
}File Assembly2.cs

// Assembly2.cs
// compile with: /reference:Assembly1.dll
// CS0122 expected
class TestAccess
{
public static void Main()
{
BaseClass myBase = new BaseClass(); // error, BaseClass not visible
outside assembly
}
}See Also

br,

Mark.

"Chien Lau" <Mo**********@grandson.pop> wrote in message
news:ug****************@tk2msftngp13.phx.gbl...
I frequently define internal UserControl-derived classes in my WinForms apps:

internal class MyUserControl:UserControl{
...
}

I'll often need to embed these controls in a Form, whose class is
contained in the same assembly as the control. As far as I know, the only
way to do this using the designer is to add the UserControl-derived object
to the toolbox and then drag it from the toolbox to the target form.

To accomplish this, I use the toolbox's Add/Remove Items functionality. When adding new UserControl(s) to the toolbox, the user is asked to choose
an assembly containing the UserControl. I browse for and choose the assembly that I'm currently working on, call it /debug/MyAssembly.dll. The problem is that the toolbox is only prepared to accept UserControl items that are
declared as "public," not those declared as "internal." For a variety of
reasons, I'd much prefer to have UserControls declared as internal if I'm
not exposing them to the outside world.

The only workaround is to temporarily change the scope of the
UserControl to public, recompile, Add the item to the toolbox, change the
modifier back to internal, and recompile again. I then have access to the
control from my toolbox. This clearly an ugly workaround. Do you know of an easier way to add internal controls to the toolbox?

Thanks...

Nov 16 '05 #2
Hi Mark,
If you are marking the controls as internal, then surely they can only be
instanciated from within that assembly .dll.
....and this is my goal. I only want to access the internal controls from
within the DLL that houses those controls.
I am also hazarding a guess that the control you have added to the toolbox
will be using a cached copy of the referenced dll so that just because you
have recompiled the original as internal will not effect the toolbox
version.


I'm not sure about this. When I recompile the control, that new version
of the control is used when I drag the respective toolbox icon on to a form.
The toolbox seems to be nothing more than a list of assemblies/class names.
The trick is getting an internal control into the toolbox. Remember, I only
want to consume the control from within the same assembly in which the
control is defined. I wouldn't expect the control to be available to OTHER
assemblies.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: TnCoder | last post by:
Hi; I just moved from vb 6.0 to vb.net. I am trying to add MS Calendar control to my toolbox. After the control is added, it is not enabled. Is there dll I have to add? Can anyone who could give...
4
by: Justin | last post by:
I am having trouble adding some of my existing controls to my toolbox in VS.NET. Here's what is going on: 1). I have an existing project that is a Windows Control Library with a bunch of...
3
by: Helmut Wagensonner | last post by:
Hi, I have created a custom textBox within a C# project. I want to put that custom textBox on a form now. I heard about a way, to place that user control onto a form within the same project,...
3
by: Casper | last post by:
Hi .Net experts, I am trying to build a user control of textbox and would like to add a public method to the object like public void CheckOptions(string str) { // codes here }
11
by: Pete Kane | last post by:
Hi All, does anyone know how to add TabPages of ones own classes at design time ? ideally when adding a new TabControl it would contain tab pages of my own classes, I know you can achieve this with...
2
by: Chip Pearson | last post by:
I'm sure that there is a simple answer but I can't find it. I need a third-part ActiveX control on a form in VB.NET 2005. I can't find anything on the built-in Forms Toolbox to add a new control...
1
by: Jedufa | last post by:
following of thread: "Adding namespaces to code behind automatically" Hello, I had quite the same problem and got further in the right direction with your suggestions, thanks. Nevertheless, I...
4
by: Steve B. | last post by:
Hi As we ship some controls with one of our application that targets web designers, we want to add items in the toolbox of the two products. With VS 2005, it is quite easy, but what about this...
8
by: Jason | last post by:
Hello, I am trying to utilitze the AJAX Control toolkit in my asp.net project. I have added a reference to AjaxControlToolkit.dll, and in my page, added these lines of code: ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.