Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Forms' does not exist in the namespace system.windows

Tags:

c#

winforms

I have just started working on c#, and was fiddling with some code sample that I got from some forum.

This code is using a namespace using system.windows.forms for which I am getting an error:

Forms does not exist in the namespace system.windows.

Also I am getting some error related to undefined functions for senddown & sendup which I believe to be in the Forms name space.

I am using visual studio 10 (with .net frame work 4.0). Any idea how to fix this error?

like image 413
John Smith Avatar asked Jul 10 '11 05:07

John Smith


People also ask

Which namespace is needed for a Windows Form application?

Forms Namespace. Contains classes for creating Windows-based applications that take full advantage of the rich user interface features available in the Microsoft Windows operating system.

How do I add a reference to system Windows Forms DLL?

Windows. Forms as a reference in your project. Right-click on 'References' , select 'Add Reference' and look under Assemblies in the dialogue. If you created your project as a Windows Forms project, that reference should have been added for you automatically.


2 Answers

Expand the project in Solution Tree, Right-Click on References, Add Reference, Select System.Windows.Forms on Framework tab.

You need to add reference to some non-default assemblies sometimes.

From comments: for people looking for VS 2019+: Now adding project references is Right-Click on Dependencies in Solution Explorer.

For people looking for VS Code: How do I add assembly references in Visual Studio Code

like image 192
VMAtm Avatar answered Sep 25 '22 15:09

VMAtm


In case someone runs into this error when trying to reference Windows Forms components in a .NET Core 3+ WPF app (which is actually not uncommon), the solution is to go into the .csproj file (double click it in VS2019) and add it to the property group node containing the target frameworks. Like this:

<PropertyGroup>     <TargetFramework>netcoreapp3.0</TargetFramework>     <UseWPF>true</UseWPF>     <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> 
like image 29
jool Avatar answered Sep 23 '22 15:09

jool