Search Unity

The type or namespace name `Windows' does not exist in the namespace `System'

Discussion in 'Scripting' started by Studio_Akiba, Apr 17, 2015.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    To prevent people from stating the obvious, I am using a WINDOWS computer, and have included System.Windows.Forms as a reference in Visual Studio, I have NOT added:
    Code (CSharp):
    1. using System.Windows;
    2. //or
    3. using System.Windows.Forms;
    To the top as this also gives me this error (or similar).

    I am trying to access "MouseEventArgs e" from the Windows VB API, but this is causing more problems than results.
    The code currently specifies it as:
    Code (CSharp):
    1. System.Windows.Forms.MouseEventArgs e
    but this throws the error in the title, changing it to Windows.Forms... does much the same thing, so does Forms... and just using MouseEventArgs eithout the prefix.

    Anyone got any solutions as to why Unity insists it is right? (BTW the System.Windows.Forms.Dll is in the Unity editor folder)
     
  2. Deleted User

    Deleted User

    Guest

    Unity decided not to implement that namespace. So you can't make use of it.
    Unity already has mouse events and such. Why not use them?
     
  3. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    That's not very useful, is there any way to add it, or any alternative that will work with Windows?
     
  4. Deleted User

    Deleted User

    Guest

  5. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    Because I am trying to drag the window around from the inside of the window, not using the taskbar.
     
  6. Deleted User

    Deleted User

    Guest

    You mean you want to be able to drag a window from the inside around without using its top? The taskbar is the bar at the bottom of your desktop.
    Have you tried the GUI class? http://docs.unity3d.com/ScriptReference/GUI.html It has a "DragWindow" method among others. I've never tried it but it may be what you need.
     
  7. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    Sorry, I am trying to drag the standalone window without touching the title bar (thing at the top), wrong naming convention.
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    System.Windows and System.Windows.Forms is for hooking into WPF and WinForms APIs of the Windows operating system respectively.

    Do you not see a problem with this?

    These are Windows OS specific things. Why would this be in Unity? Unity is intended for OS independent development... WinForms doesn't exist on anything else but Windows.

    Furthermore, the events in the WinForms API are directly as the result of the WinForms API. The mouse events that fire have to occur IN A WINFORM. Unity doesn't use WPF or WinForms for pretty much nothing. So the events won't actually fire correctly, if at all, if you hooked into them.

    What you might be trying to do is hook into the Windows actual Window manager and input event system. This is not WPF or WinForms.

    You can actually hook into this using the 'interop/pinvoke' capabilities in Mono.
    http://www.mono-project.com/docs/advanced/pinvoke/

    It can get a little complicated, and you really need to be well versed in the Windows operating system API.




    Now, I want to touch on what you're attempting to accomplish though...

    You want to hook into the mouse events to move the window around? Are you telling me you're going to hijack the mouse from the user, move it to the title bar, simulate a click and drag, to move the window?

    Why not just set the position of the window directly?

    Which... you can do via interop.

    http://answers.unity3d.com/questions/13523/is-there-a-way-to-set-the-position-of-a-standalone.html
     
  9. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I am not trying to hijack the mouse to move the window, I am trying to give the USER the ability to move the window (in standalone windowed mode) without using the title bar.
     
  10. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    Ok...

    So initiate a drag on whatever in game event you want (mouse down? when they click an in game button? whatever).

    Then every frame during that drag find the change in mouse position (use Input.mousePosition, just store it every frame and subtract the current from the one last frame).

    Then use interop to set the window position to the current position plus this change.
     
  11. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    The better question is - why?
     
  12. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    I was thinking asking the same thing.

    But then I considered maybe they want to have some strange user experience game. Where there's some like 4th wall breaking interaction, like you click to drag something in the game world... say a chain... and it yanks the window around on your desktop.

    I could think of some fun gameplay ideas to do with that... like a monster whose attack is to push the window off screen. And you have to fight and drag it back on screen so you can see what you're doing.
     
  13. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    The main use of this is not in the actual game, but in our launcher, which we are toying with the idea of removing the title bar of, so there would be no other way of dragging it round, that is why I need to work out if it is even possible (or how to do it) before I spend the better part of a few days implementing a feature that will have to be removed.
     
  14. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,539
    Well, I explained to you how to do it.