How to use the System.Windows.Forms.dll inside Unity (Windows Only).

So I have been playing around with .Net dlls inside unity and wanted to check some functions inside the System.Windows.Forms.dll in order to access the primary monitor screen size but found out that Unity’s .Net embebed runtime doesnt include the System.Windows.Forms.dll so here is a way to include it in your project.

Go and grab System.Windows.Forms.dll and System.Deployment.dll from “C:/Windows/Microsoft.NET/Framework/v2.0.50727/” and copy those dlls to your project at “Assets/Plugins/” , after that, you are almost done, you just need to go to “Edit -> Project Settings -> Player” in Unity and go to the “Other Settings”  tab and under the Optimization label on the “API Compatibility Level”  just select “.Net 2.0″ instead of “.Net 2.0 Subset”.

Then you are good to go and use the dll functions, just create a small script like this to check it out:

I havent tested that much if this will work on other platforms will give you warnings or problems but seemed to work for me, if you have any problems making it work let me know.

3 Responses to “How to use the System.Windows.Forms.dll inside Unity (Windows Only).”

  1. Juan Sebastian says:

    Which version of Unity are you using? 64?, if I remember well it used to work in the 32bit version :/

  2. Jason says:

    This did not work for me (it caused Unity to crash). I also did not have the second version of System.Windows.Forms.dll and System.Deployment.dll files available in “C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0″

    Jason

  3. Amir says:

    Copying System.Windows.Forms.dll from “C:/Windows/Microsoft.NET/Framework/v2.0.50727/” does not work for me.
    Instead I copied it from “C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0” and it worked fine.

    It seems the two dlls are different at least in their sizes.