Hello i was wondering how can i import System.Windows.Forms in my asp.net class file? It actualy marks it as error with no error suggestions. Do i need to reference somewere?
2 Answers
You need to add a reference to the correct assembly to your project in Visual Studio before you can import the namespace.
But I question whether this is a good idea. While it is possible to create instances of the windows forms classes and controls, you cannot add or show any of those controls with asp.net pages.
Some of the Windows forms types have non-visual behavior features you may want to use, and so I have seen this done to good effect in the past. But even then, it's usually a bad idea, as the Windows Forms controls are also memory hogs relative to the web and can hurt performance of your site. And remember that these controls still won't keep their state across multiple http requests. There's almost always a better way to do it.

- 399,467
- 113
- 570
- 794
The real question is why would you want to import System.Windows.Forms
inside of any type of asp.net project? You are doing something wrong. The other thing you can try to do is manually reference the dll / if you have a web.config
file you can add it as an assembly:
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
See this for more details