Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing System.Windows.Forms from a Class Library

Tags:

c#

.net

winforms

I am creating a Class Library and need to inherit from PictureBox: public class Picture : PictureBox { ... } but Forms is not available when I try to add a using directive for it at the top of my Class Library: using System.Windows.Forms;. I know that I can get it to work by right-clicking Referenced in Solution Explorer and selecting Add Reference, then adding the System.Windows.Forms assembly from the list.

But is it okay to do this? Is it okay to reference WindowsForms from a Class Library?

like image 562
spike.y Avatar asked May 05 '14 11:05

spike.y


1 Answers

It is totally okay to do this.

System.Windows.Forms is just an assembly like any others. There is no special treatment to the project file, as with for example Office add-ins.

You can safely add this assembly to your project file.

like image 150
Patrick Hofman Avatar answered Oct 31 '22 21:10

Patrick Hofman