-
Jul 3rd, 2014, 04:08 PM
#1
Thread Starter
Junior Member
[RESOLVED] Using Class Library in other Projects.
I have 4 projects in my solution. In short, they all use datagridviews and I want their formatting to be uniform.
I was using a module with a method to set the formatting but I needed a copy of the module in each of the projects.
If I alter the code in 1 I have to copy it to them all. I created a class library so all projects can reference it and tried to generate the code, but it won't let me reference the Windows.System.Forms namespace for the DataGridView. Fair enough, but is there a better way to achieve what I want without creating a 'Formatting' windows Forms project instead?
Thanks
-
Jul 3rd, 2014, 04:11 PM
#2
Re: Using Class Library in other Projects.
No reason you can't reference the system.windows.forms namespace from within a dll. It isn't available by default, but you can add it as a reference to the class library project and then use it like any other library.
I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
My war with a browser-redirect trojan
-
Jul 3rd, 2014, 04:52 PM
#3
Re: Using Class Library in other Projects.
As dolot pointed out, one of the differences between a Windows Form Application and a Class Library is that the Windows Form Application references the System.Windows.Forms namespace by default while the Class Library does not. You can confirm this by going to your project's properties(project > -project name- properties) and going to the References tab. The references added by default by the Windows Form Application are(depending on Framework):
- System
- System.Core
- System.Data
- System.Data.DataSetExtensions
- System.Deployment
- System.Drawing
- System.Windows.Forms
- System.Xml
- System.Xm.Linq
Where as with the class library the references added by default are:
- System
- System.Core
- System.Data
- System.Data.DataSetExtensions
- System.Xml
- System.Xm.Linq
-
Jul 3rd, 2014, 07:48 PM
#4
Thread Starter
Junior Member
Re: Using Class Library in other Projects.
Ahh thank you.
Was weird, using the references tab I couldn't find it, but by right clicking on the project in the Solution Explorer and clicking add reference I could find it.
Many thanks
-
Jul 4th, 2014, 04:02 AM
#5
Re: [RESOLVED] Using Class Library in other Projects.
If you want to create a library project with WinForms support then you should create a Windows Forms Control Library project rather than a Class Library project if you can. They both output a DLL but the former has all the same references as a Windows Forms Application project. It also adds a user control by default rather than a class, but you can delete that easily enough. That project template was only available in paid editions of VS in previous versions, i.e. not in Express editions. I'm not sure whether the same is true for the most recent versions as I haven't really used VS Express in 2012 or 2013.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|