Wiimote的C#编码问题

Wiimote的C#编码问题,c#,wiimote,C#,Wiimote,目前正在使用Wii遥控器创建虚拟现实头部跟踪系统的工作遇到了一个错误 类***可以设计,但不是文件中的第一个类。Visual Studio要求设计者使用文件中的第一个类。移动类代码,使其成为文件中的第一个类,然后再次尝试加载设计器 我已将代码拆分到不同的页面,但收到相同的错误。这是我正在研究的代码: namespace WiiDesktopVR { class Point2D { public float x = 0.0f; public floa

目前正在使用Wii遥控器创建虚拟现实头部跟踪系统的工作遇到了一个错误

类***可以设计,但不是文件中的第一个类。Visual Studio要求设计者使用文件中的第一个类。移动类代码,使其成为文件中的第一个类,然后再次尝试加载设计器

我已将代码拆分到不同的页面,但收到相同的错误。这是我正在研究的代码:

namespace WiiDesktopVR
{
    class Point2D
    {
        public float x = 0.0f;
        public float y = 0.0f;
        public void set(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
    }

    public class WiiDesktopVR : Form
    {
        struct Vertex
        {
            float x, y, z;
            float tu, tv;

            public Vertex(float _x, float _y, float _z, float _tu, float _tv)
            {
                x = _x; y = _y; z = _z;
                tu = _tu; tv = _tv;
            }

            public static readonly VertexFormats FVF_Flags = VertexFormats.Position | VertexFormats.Texture1;
        };

        Vertex[] targetVertices =
        {
            new Vertex(-1.0f, 1.0f,.0f,  0.0f,0.0f ),
            new Vertex( 1.0f, 1.0f,.0f,  1.0f,0.0f ),
            new Vertex(-1.0f,-1.0f,.0f,  0.0f,1.0f ),
            new Vertex( 1.0f,-1.0f,.0f,  1.0f,1.0f ),
        };
    }
}

谢谢

点2D
移动到文件底部。最佳实践表明,每个文件应该只有一个类,所以接受Stuart的建议并将其移动到另一个文件将是最好的

namespace WiiDesktopVR
{
    public class WiiDesktopVR : Form
    {
        struct Vertex
        {
            float x, y, z;
            float tu, tv;

            public Vertex(float _x, float _y, float _z, float _tu, float _tv)
            {
                x = _x; y = _y; z = _z;
                tu = _tu; tv = _tv;
            }

            public static readonly VertexFormats FVF_Flags = VertexFormats.Position | VertexFormats.Texture1;
        };

        Vertex[] targetVertices =
        {
            new Vertex(-1.0f, 1.0f,.0f,  0.0f,0.0f ),
            new Vertex( 1.0f, 1.0f,.0f,  1.0f,0.0f ),
            new Vertex(-1.0f,-1.0f,.0f,  0.0f,1.0f ),
            new Vertex( 1.0f,-1.0f,.0f,  1.0f,1.0f ),
        };
    }

    class Point2D
    {
        public float x = 0.0f;
        public float y = 0.0f;
        public void set(float x, float y)
        {
            this.x = x;
            this.y = y;
        }
    }
}

错误消息告诉您表单必须是文件中的第一个类。将Point2D移到另一个文件。好的,谢谢,我会尝试的。我还需要将“Point2D”文件链接到此文件中吗?不,编译器将负责链接这些文件。好的,谢谢,我会尝试的。我还需要将“Point2D”文件链接到此文件中吗?很抱歉,我以前没有使用过C#。如果类位于同一命名空间中,则不会使用。如果它们在不同的名称空间中,您只需要在文件顶部的名称空间中添加一个using语句。