XNA和Windows表单 [英] XNA And Windows forms

查看:83
本文介绍了XNA和Windows表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XNA进行演示(Demoscene),但我想首先弹出一个窗口,您可以在其中选择设置.但是当我编写一个代码来打开一个新的Game1()实例时,我得到了这个(InvalidOperationException):

歌剧表演的开始,融为一体的开始. Bruk Form.ShowDialog我stedet.

它将英语翻译为:在单个线程中启动新的messageloop(?)不是有效的操作.请使用Form.-ShowDIalog.

我将showDialog用于我的设置表单.什么需要改变?

资料来源:

I am working on a demo(Demoscene) using XNA, but i want a window to pop out first, where you can select your settings. But when i code a button to Open a new Game1() instance, i get this(InvalidOperationException):

Det er ikke en gyldig operasjon å starte en ny meldingsløkke i en enkelt tråd. Bruk Form.ShowDialog i stedet.

Which translates in english to It is not a valid operation to start a new messageloop(?) in a single thread. use Form.-ShowDIalog instead.

I am using showDialog for my settings form. What needs change?

Source:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tg12
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            button1.Text = "Start!";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Game1 game = new Game1();
            game.Run();
        }
    }
}


Program.cs:


Program.cs:

using System;

namespace Tg12
{
#if WINDOWS || XBOX
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Form1 form = new Form1();
            form.ShowDialog();
        }
    }
#endif
}

推荐答案

好吧,我不确定您在做什么是一个好主意,但是我唯一可以看到的做到这一点的方法现在,在我疲惫的心态中,是开始一个新线程.即

Well I am not sure what you are doing is a good idea but the only way I can see to do this right now in my tired state of mind is to start a new thread. i.e.

private void button1_Click(object sender, EventArgs e)
{
    System.Threading.Thread thStartGame = new System.Threading.Thread(StartGame);
    thStartGame.Start();
}

private void StartGame()
{
    Game1 game = new Game1();
    game.Run();
}


这篇关于XNA和Windows表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆