Results 1 to 5 of 5

Thread: [RESOLVED] Using Class Library in other Projects.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    24

    Resolved [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

  2. #2
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Music city, U.S.A.
    Posts
    1,253

    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

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    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):
    1. System
    2. System.Core
    3. System.Data
    4. System.Data.DataSetExtensions
    5. System.Deployment
    6. System.Drawing
    7. System.Windows.Forms
    8. System.Xml
    9. System.Xm.Linq


    Where as with the class library the references added by default are:
    1. System
    2. System.Core
    3. System.Data
    4. System.Data.DataSetExtensions
    5. System.Xml
    6. System.Xm.Linq
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2011
    Posts
    24

    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

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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
  •  



Click Here to Expand Forum to Full Width