【发布时间】:2015-07-21 17:02:22
【问题描述】:
我正在尝试让一个 winform 打开一个 Xna 表单。在网上查找我发现的最好方法是首先通过 program.cs 打开表单,然后放置一个 if 语句来检查您是否点击了 winform 上的开始按钮,该按钮将给出 DialogResult.OK 。我知道我需要使用 ShowDialog 启动表单,但是我用我当前的代码得到了两个表单。它打开一个,我关闭它,它打开另一个 winform,当你关闭它时,你会得到 Xna 表单。有什么建议么? 这是我的代码:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main(string[] args)
{
using(Form1 form = new Form1())
{
form.ShowDialog();
if(form.ShowDialog() == DialogResult.OK)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
}
}
}
这是我的按钮代码:
private void button1_Click(object sender, EventArgs e)
{
compotents comps = new compotents();
comps.mass = textBox1.Text;
comps.velocity = textBox2.Text;
comps.gravity = textBox3.Text;
button1.DialogResult = DialogResult.OK;
this.Close();
}
(compotents 是我用来存储变量并以 xna 形式使用它们的类)
【问题讨论】: