7

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?

4
  • Yes, that is fine. Very hard to see why this spooks you. It cannot possibly be a problem because whatever project uses your class also needs to add a reference to System.Windows.Forms. Without it, the compiler will complain because it has no idea what a PictureBox class might be. Commented May 5, 2014 at 11:37
  • Thank you @UlugbekUmirov and HansPassant. Commented May 5, 2014 at 11:41
  • This answer will be more useful: stackoverflow.com/questions/57509951/… Commented Jun 21, 2021 at 13:09
  • This answer will be more useful: stackoverflow.com/questions/57509951/… Commented Jun 21, 2021 at 13:10

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh, you can close if you like. I thought I had already accepted the answer.
Just FYI, @spike.y; Closing is not for questions that are solved. Questions here aren't so much "support requests" as part of a searchable repository of information that could be helpful to people in the future. Further answers are always welcome, in fact, in case someone has an alternate solution that could apply. That may not help you, but it could help a future reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.