Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Vox Nephila · Jan 23, 2013 at 04:16 PM · c#dll

using System.Windows.Forms

Here is the problem code, I took out everything but the parts I'm having issues with. Note that my dll is stored in the plugins folder.

 using UnityEngine;
 using System.Collections;
 using System.Windows.Forms;
 
     private void MoveCursor()
     {
        // Set the Current cursor, move the cursor's Position,
        // and set its clipping rectangle to the form. 
 
        this.System.Windows.Forms.Cursor = new System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle);
        Position = new Point(System.Windows.Forms.Cursor.Position.X - 50, System.Windows.Forms.Cursor.Position.Y - 50);
        System.Windows.Forms.Cursor.Clip = new Rectangle(this.Location, this.Size);
     }

The MoveCursor() function was copied directly from Cursor.Position Property.

The issue is that when I go to compile this script, I get the following error.

 Internal compiler error. See the console log for more information. output was:
 Unhandled Exception: System.TypeLoadException: Could not load type 'System.Windows.Forms.Cursor' from assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
 
   at (wrapper managed-to-native) System.MonoType:GetMethodsByName (string,System.Reflection.BindingFlags,bool,System.Type)
 
   at System.MonoType.GetMethods (BindingFlags bindingAttr) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.MemberCache.AddMethods (BindingFlags bf, System.Type type) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.MemberCache.AddMethods (System.Type type) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.MemberCache..ctor (IMemberContainer container) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeHandle..ctor (System.Type type) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeHandle.GetTypeHandle (System.Type t) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeHandle.GetMemberCache (System.Type t) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeManager.MemberLookup_FindMembers (System.Type t, MemberTypes mt, BindingFlags bf, System.String name, System.Boolean& used_cache) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeManager.RealMemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.TypeManager.MemberLookup (System.Type invocation_type, System.Type qualifier_type, System.Type queried_type, MemberTypes mt, BindingFlags original_bf, System.String name, IList almost_match) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.MemberLookup (Mono.CSharp.CompilerContext ctx, System.Type container_type, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.MemberLookupFinal (Mono.CSharp.ResolveContext ec, System.Type qualifier_type, System.Type queried_type, System.String name, MemberTypes mt, BindingFlags bf, Location loc) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.New.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in <filename unknown>:0 
 
   at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in <filename unknown>:0

I am extremely new to C#, but I have worked with many other languages so know my basics, just not much oop. Any help is appreciated. Also, I am using this so I can set the mouse position (as in, setting it back to its original position after someone lets off the right click to create the illusion that it was frozen in place, unless there is a better way to do this).

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Oct 31, 2013 at 12:56 PM 0
Share

There's no Unity-way of setting the cursor unfortunately, you'd have to rely on System API. See my answer here.

3 Replies

· Add your reply
  • Sort: 
avatar image
10

Answer by GTaveira · Oct 31, 2013 at 11:41 AM

Copy the 'System.Windows.Forms.dll' to your "Assets/Plugins/" folder. However, it only worked for me when I got the DLL version from: "C:\\Program Files (x86)\\Unity\\Editor\\Data\\Mono\\lib\\mono\\2.0". Apparently, there are different versions of this DLL spread throughout the system.

Also, make sure you go to "Edit -> Project Settings -> Player" in Unity, go to "Other Settings" and on the "API Compatibility Level" select ".Net 2.0" instead of ".Net 2.0 Subset".

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RodrigoSeVeN · Jul 27, 2017 at 03:48 PM 0
Share

I did some quick testing, and setting to .Net 2.0 was enough, so I didn't need to copy the file manually.

avatar image
1

Answer by Dave-Carlile · Jan 23, 2013 at 04:20 PM

I would be very surprised if using anything from System.Windows.Forms would work well in Unity.

I would spend my efforts implementing a software cursor, rather than using the system cursor...

http://wiki.unity3d.com/index.php?title=Custom_2D_Pointer

You can draw it whereever you want to that way. Might need to move it using relative movement rather than the specific position reported by Input.mousePosition.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vox Nephila · Jan 23, 2013 at 04:22 PM 0
Share

I actually do have a gui cursor script at the moment, I use

http://wiki.unity3d.com/index.php/Custom_$$anonymous$$ouse_Pointer

I'm unsure of how to move it relatively, could you perhaps provide some insight on that?

avatar image
0

Answer by whydoidoit · Jan 23, 2013 at 04:17 PM

If this is indeed a Unity project then you cannot use System.Windows.Forms!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Vox Nephila · Jan 23, 2013 at 04:23 PM 0
Share

What's funny is I saw an answer here on these forums that was telling someone to use it, or implement a gui cursor. :x

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

When I build my game it gives me this error 'Assets/Builds/Build_0.01_Data/Managed/Assembly-CSharp.dll' shouldn't be queried by IsAssemblyCompatible, missing IsInternalOrCompiledAssembly check ? 2 Answers

Can you run unmanaged plugins from unity plus? 1 Answer

Can Unity track the changes I made to my DLL? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges