none
Need windows forms class libraries in a stand alone console application RRS feed

  • Question

  • I need to use a windows forms class library in a stand alone console application. For example the "Rectangle" class under namespace ...Drawing. This "Rectangle" class is needed for some functions inside it like "intersect" etc. Is there a way to use it in my console app?. Some languages have similar in-built library. I know that I can create my custom class and functions for "Rectangle", but that involves some amount of time consuming manual coding. 

    Friday, March 20, 2015 6:07 PM

Answers

  • Adding a reference and setting a 'using' line are two different things.  Adding a reference tells your application to request access to a memory loaded library, while adding a 'using' line tells your compiler to assume that the namespace following 'using' might be prefixed to any class, struct, enum, or whatever else you write into your code.

    You can either look in the SOLUTION EXPLORER in Visual Studio for the REFERENCES folder, right click on that, then left-click ADD REFERENCE, or you can open the PROJECT menu and go to PROPERTIES, then the REFERENCES tab, or something.  I really don't know what Visual Studio looks like if it's bigger than 2008.  2008 was the last useful version.

    So whatever your VS version is, google how to add references.

    Saturday, March 21, 2015 8:07 AM

All replies

  • Just add a reference to System.Drawing, System.Windows.Forms, or whatever else you need in your console application project.

    Bear in mind that this will not necessarily provide your console application with a Windows Form based GUI - it will strictly give you access to programmatic functions and features.


    Content Removed

    Friday, March 20, 2015 6:15 PM
  • Well, thanks Andrew for the reply.

    Now if  I add "using System.Windows.Forms", in my console app, it shows an error.

    Any ideas?

    Saturday, March 21, 2015 6:45 AM
  • Adding a reference and setting a 'using' line are two different things.  Adding a reference tells your application to request access to a memory loaded library, while adding a 'using' line tells your compiler to assume that the namespace following 'using' might be prefixed to any class, struct, enum, or whatever else you write into your code.

    You can either look in the SOLUTION EXPLORER in Visual Studio for the REFERENCES folder, right click on that, then left-click ADD REFERENCE, or you can open the PROJECT menu and go to PROPERTIES, then the REFERENCES tab, or something.  I really don't know what Visual Studio looks like if it's bigger than 2008.  2008 was the last useful version.

    So whatever your VS version is, google how to add references.

    Saturday, March 21, 2015 8:07 AM
  • What about submitting console app codes in online contests???? I don't think references will work. Or am I mistaken or just too lazy again??

    • Edited by OrionWalli Saturday, March 21, 2015 8:36 AM
    Saturday, March 21, 2015 8:34 AM
  • Hello OrionWalli,

    >>What about submitting console app codes in online contests????

    What do you mean about the “in online contests”? If you mean you would upload your project to a network store place, it of course does not work since these window form assemblies are stored in GAC and they are do not uploaded to your specific network store location.

    You could write yourselves assemblies or copy them from GAC to your project application directory and add a reference to these copied assemblies.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 23, 2015 9:28 AM
    Moderator
  • What about submitting console app codes in online contests???? I don't think references will work. Or am I mistaken or just too lazy again??

    I've looked at this follow-up question about a dozen times and I think I finally get it:

    I believe that what you mean is, "How do I communicate that such a reference exists when Visual Studio doesn't add it automagically, and all I can post is my raw code?"

    When experienced DotNET programmer looks at your raw code and sees, "using System.Windows.Forms;" or "private System.Windows.Forms.Control myControl;" etc, that programmer will know that you added the reference to System.Windows.Forms.  If you didn't, then you couldn't use it.

    Alternatively, you can add a comment to the effect that the code requires a reference to System.Windows.Forms.

    Wednesday, April 15, 2015 10:36 PM