Reputation: 3824
Is it possible to use the TreeView Class in a class library.
I want to make a method where I pass a Treeview from windows form , I tried to import System.Windows.Forms but it is not found and I cannot find any nuget package to install.
I want to do something like this:
public void MyMethod(TreeView tree){tree.Nodes.Add("Something");}
Thanks.
Upvotes: 0
Views: 272
Reputation: 243
In Solution Explorer: Right click on the class library project, select Add > Reference. On the left sidebar choose Assemblies > Framework. Check System.Windows.Forms and click Ok.
I would caution against adding this reference in your existing class library unless you want it to be specifically only for WinForms. Perhaps a cleaner approach would be to create a new class library, say .WinForms, and add a project reference to the original project and a Framework reference to System.Windows.Forms as I described above. This would keep the rest of your code separated out from the WinForms code in the base project, and then it could be used in other contexts without WinForms.
Upvotes: 1