1

joystick.cs

using System;
using Microsoft.DirectX.DirectInput;

namespace gameproject
{
    /// <summary>
    /// Description of device.
    /// </summary>
    class joysticks
    {

        public static Device joystick;
        public static JoystickState state;

        public static void InitDevices() //Function of initialize device
        {
            //create joystick device.
            foreach (DeviceInstance di in Manager.GetDevices(
                DeviceClass.GameControl,
                EnumDevicesFlags.AttachedOnly))
            {
                joystick = new Device(di.InstanceGuid);
                break;
            }

            if (joystick == null)
            {
                //Throw exception if joystick not found.
            }

            //Set joystick axis ranges.
            else {
                foreach (DeviceObjectInstance doi in joystick.Objects)
                {
                    if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
                    {
                        joystick.Properties.SetRange(
                            ParameterHow.ById,
                            doi.ObjectId,
                            new InputRange(-5000, 5000));
                    }

                }

                joystick.Properties.AxisModeAbsolute = true;
                joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);

                //Acquire devices for capturing.
                joystick.Acquire();
                state = joystick.CurrentJoystickState;
            }
        }

        public static void UpdateJoystick()   // Capturing from device joystick
        {
            //Get Joystick State.
            if(joystick!=null)
                state = joystick.CurrentJoystickState;
        }

    }
}

この行で、エラーが発生しました。

    joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive 
| CooperativeLevelFlags.Background);

エラー、

Error 1 The type 'System.Windows.Forms.Control' is defined in an 
assembly that is not referenced.
     You must add a reference to assembly 'System.Windows.Forms...

XNA3.0と.NET3.5に取り組んでいますが、そのエラーはどういう意味ですか?

4

1 に答える 1

2

SetCooperativeLevelオブジェクトをSystem.Windows.Forms.Control最初のパラメーター(nullがある場合)として受け取るため、アプリケーションでこのクラスが定義されているアセンブリを参照する必要があります。アプリ/ゲームからSystem.Windows.Forms.dllの参照を追加して、試してみてください。使用しているコードが、内部で参照していない他のクラスを使用している場合は問題ありませんが、それらがパブリックである場合(パラメーターであるか、呼び出しているメソッドから返されるなど)、アセンブリを参照する必要があります。それらのタイプが定義されています。

同様のstackoverflowの投稿: デバッグエラー「タイプ'xx'は参照されていないアセンブリで定義されています」

于 2011-04-09T10:52:38.097 に答える