473,586 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User control sharing between several projects

Hi, I have a user control which I like to use in several projects (winforms)
in the same solution. Inside lets say Winapp1 , When adding a reference to
this control, I can dynamically or statically create it and when running the
application it is correctly drawn on the form. But when I take out the
reference to this control in Winapp1, reference it in a utility project,
then reference the utility project in Winapp1 or Winapp2, instantiate the
utility.mContro l, it doesn't get drawn on the form and I get no errors.
I did a quick check, I added 2 instances of the user control referenced in
the utility project to my form, using
messagebox.show (myform.control s.count), it displays 2 which means that
controls are added but not being able to be drawn. Of course I double checked
properties such as visible = true........... ...
Thanks in advance for any help
Jun 27 '08 #1
5 1917
On Tue, 22 Apr 2008 05:01:00 -0700, SalamElias
<el******@onlin e.nospamwrote:
>Hi, I have a user control which I like to use in several projects (winforms)
in the same solution. Inside lets say Winapp1 , When adding a reference to
this control, I can dynamically or statically create it and when running the
application it is correctly drawn on the form. But when I take out the
reference to this control in Winapp1, reference it in a utility project,
then reference the utility project in Winapp1 or Winapp2, instantiate the
utility.mContr ol, it doesn't get drawn on the form and I get no errors.
I did a quick check, I added 2 instances of the user control referenced in
the utility project to my form, using
messagebox.sho w(myform.contro ls.count), it displays 2 which means that
controls are added but not being able to be drawn. Of course I double checked
properties such as visible = true........... ...
Thanks in advance for any help
When you instantiate the control, are you adding it to its parent's
Control collection?
Jun 27 '08 #2
Hi Salam,

Based on my understanding, you have Control Library project which contains
a UserControl and a Class Library project and some Windows Application
projects in a solution.

If you add add a reference to the Control Library project in the Class
Library project and then add a reference to the Class Library project in
the Windows Application projects and then add the UserControl on the form,
the UserControl doesn't appear on the form when the application is run.

If I'm off base, please feel free to let me know.

I performed a test based on your description, but didn't reproduce the
problem on my side. The steps of my test are as follows:

1. Create a solution and add a Control Library project and a Class Library
project and a Windows Application project to the solution. Add a
UserControl in the Control Library project.

2. Derive the Class1 in the Class Library project from the UserControl in
the Control Library project:
namespace ClassLibrary1
{
public class Class1:WindowsC ontrolLibrary1. UserControl1
{
}
}

3. Build the solution.

4. Drag the UserControl from Toolbox and drop it onto the form in the
Windows Application project. A reference to the Control Library project is
added to the Windows Application project automatically. Build and run the
application and the UserControl appears on the form.

5. Remove the reference to the Control Library project from the Windows
Application project and add a reference to the Class Library project in the
Windows Application project.

6. Add the following lines of code in the Form's Load event handler to add
the UserControl on the form dynamically:
private void Form1_Load(obje ct sender, EventArgs e)
{
ClassLibrary1.C lass1 mycontrol = new ClassLibrary1.C lass1();
this.Controls.A dd(mycontrol);
}

7. Build the solution. An compilation error occurs:
The 'WindowsControl Library1.UserCo ntrol1' is defined in an assembly that is
not referenced. You must add a reference to the assembly "...".

Is there any difference between your solution and mine?

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #3
yes, you are almost correct, one difference is my user control is compiled as
a dll and referenced in my utility class library as follows.

Public Class Gauge
Inherits AGauge.AGauge

Then in my windows app I do
Dim Gauge1 Gauge = New Gauge()
but I don't get a compiltaion error and even as I said my message box
indicates that there is a new control added to the form
"Linda Liu[MSFT]" wrote:
Hi Salam,

Based on my understanding, you have Control Library project which contains
a UserControl and a Class Library project and some Windows Application
projects in a solution.

If you add add a reference to the Control Library project in the Class
Library project and then add a reference to the Class Library project in
the Windows Application projects and then add the UserControl on the form,
the UserControl doesn't appear on the form when the application is run.

If I'm off base, please feel free to let me know.

I performed a test based on your description, but didn't reproduce the
problem on my side. The steps of my test are as follows:

1. Create a solution and add a Control Library project and a Class Library
project and a Windows Application project to the solution. Add a
UserControl in the Control Library project.

2. Derive the Class1 in the Class Library project from the UserControl in
the Control Library project:
namespace ClassLibrary1
{
public class Class1:WindowsC ontrolLibrary1. UserControl1
{
}
}

3. Build the solution.

4. Drag the UserControl from Toolbox and drop it onto the form in the
Windows Application project. A reference to the Control Library project is
added to the Windows Application project automatically. Build and run the
application and the UserControl appears on the form.

5. Remove the reference to the Control Library project from the Windows
Application project and add a reference to the Class Library project in the
Windows Application project.

6. Add the following lines of code in the Form's Load event handler to add
the UserControl on the form dynamically:
private void Form1_Load(obje ct sender, EventArgs e)
{
ClassLibrary1.C lass1 mycontrol = new ClassLibrary1.C lass1();
this.Controls.A dd(mycontrol);
}

7. Build the solution. An compilation error occurs:
The 'WindowsControl Library1.UserCo ntrol1' is defined in an assembly that is
not referenced. You must add a reference to the assembly "...".

Is there any difference between your solution and mine?

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 27 '08 #4
Hi Salam,

Thank you for your reply!

Since I couldn't reproduce the problem on my side, it would be better if
you could reproduce the problem in a simple solution and send it to me. To
get my actual email address, remove 'online' from my displayed email
address.

I look forward to your reply!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #5
Hi Salam,

Thank you for your sample solution!

I run the sample application and did see the problem.

After looking at the source code, I find the reason that causes the
problem. You create an instance of the AGauge.AGauge class inside the Gauge
class and initialize this instance in the constructor, but the Gauge class
itself is not initialized at all. Then you add an instance of the Gauge in
a form's Controls collection rather than the nested AGauge control within
the Gauge instance, so nothing appears on the form.

Change the code in the sub New within the Gauge class as follow can solve
the problem:
Public Class Gauge
Inherits AGauge.AGauge

Public Sub New(ByVal gaugeName As String, ByVal gaugeCaption As
String)
_AGauge = New AGauge.AGauge

' replace "_AGauge" with "Me"
Me.BaseArcColor = System.Drawing. Color.Gray
Me.BaseArcRadiu s = 80
Me.BaseArcStart = 135
Me.BaseArcSweep = 270
...
End Sub
...
End Class

In addition, I don't think it's necessary to create an instance of the
AGauge.AGauge class within the Gauge class because Gauge is a kind of
AGauge.AGauge already.

BTW, in my initial test to try to reproduce the problem, I created C#
projects. As I said in my first reply, the compilation fails if I only add
a reference to the Class Library project in the Windows Application
project. But it's not true in VB.NET projects. So it seems that the
mechanism of C# compiler is a little different from that of VB.NET compiler.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #6

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

Similar topics

1
1940
by: Simon Neve | last post by:
Hello, This question is related to sharing .Net projects across solutions and is reposted from the SourceSafe group. We have several different solutions and want to share common assemblies across them. Is it best to share the project and its files to each solution (each solution has it's own shared project), or have each solution point...
5
13501
by: Tinius | last post by:
I have created a class which I wish to reuse amongst several projects. But each time I Add the class to a new project, it creates a copy of that class in the folder of the new project. This means that when I make changes to that class, I have to apply the same changes to all the projects. Is there a setting that I have missed such that I...
16
2218
by: Robert W. | last post by:
I'm building a solution that has 1 component for the Desktop and 1 component for the Pocket PC. (Though this isn't a mobile question). I have a data library that will be shared on both platforms. So I've adopted the approach of having two projects share the same set of files. In my case, I have two similarly named projects: DataObjects...
0
1203
by: Daniel | last post by:
Hi! I have several projects (approx 50) that includes basically the same files such as <atlcom.h> and <comdef.h>. The projects are set up to use a precompiled header wich includes these header files (<atlcom.h> and <comdef.h>) and that works fine. But since these files are used in all the projects and every project have a separate...
2
1388
by: Matze | last post by:
I have setup Visual Studio to work with a VSS-Server. (Source Off Site) I dont see a way to share and later branch my project. File -> Source Control -> Share is grayed out. What is the best way then to share/branch? SOS-Client is 3.5.3 / Server is 3.5.2 I had some bad experiences doing VSS-actions with a client different than VS.NET...
3
1360
by: brynja | last post by:
Hi .. I´m using web user control on my project group. Now i´m using web user control for each project and it works fine, but now I want to share some controls for various project and I dont know how? I have created a folder beside all my project and put one control there. I know how to go up one folder with the "~/" tag but how can ...
3
1710
by: Michael | last post by:
Hi all.. I have a solution containing 5 projects, one of which is a custom control. In one of the projects, I dragged the .ascx file from the custom control project and dropped it onto a form. I've also referenced the custom control project. Everything looks good, I can see properties and events, etc. The solution builds with no errors. ...
0
822
by: Vignesh | last post by:
Iam Having 3 separate VB.NET Windows projects (MainProject, Project1, Project2). From MainProject iam calling Project1 & Projct2. Project1 contains a user control.Project2 also contains a User control. MainProject Contains a WindowsForm where i want to host a User Control. In the MainProject (WindowsForm) i want to load the usercontrol in...
7
3159
by: crowl | last post by:
VS.2003, .NET Framework 1.1, C# My goal: Creating a dll (helper.dll) which contains some UserControls and some other helpful classes in order to use it in other projects. Symtoms: The inital use of the UserControl component works. However, if the Helper Project is recompiled, the UserControl does not work
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.