我正在尝试为运行的旧手持设备开发一个应用。NET3.5 WIN CE 5,但是我似乎无法克服基本的障碍切换表格!
我开始使用
Application.Run(new frm_class());
但是,这是在打开2个表格后开始崩溃的。
我尝试了。
this.hide();
frm_class frm = new frm_class();
frm.show();
然后最终成为加载表单的恒定循环然后我看到有人写了一个非常简单的课来处理这个。
public static void switchForm(Form newForm, Form oldform)
{
newForm.Show();
oldform.Hide();
oldform.Dispose();
}
通过
致电 frm_class frm = new frm_class();
switchform(frm,this);
加载第二个表单时关闭应用程序。
这似乎是如此愚蠢,但我找不到仅通过简单表格导航的方法,即关闭此表格,然后打开此形式,反之亦然!
任何人可以帮忙吗?
Application.Run(new frm_class());
将启动一个消息循环,并使指定的表单可见,然后等待其关闭。一旦指定的表单关闭,消息循环将终止。 oldform.Dispose();
将处置(并关闭)表格,而不是隐藏。
您的第二个解决方案似乎是您应该采用的,不应该循环。如果您再次创建相同的表单,请确保代码不在constructor或form_load事件中。您可以发布围绕此的代码吗?
您还可以从Application.Run()
中删除new frm_class()
参数。这将创建一个恒定的运行消息循环。只是不要忘记在某个时候致电Application.Exit()
。
您应该确保在无参数Application.Run()
之前可见表格,因为此CodeBlock内部的执行不会继续从您的表单内部调用Application.Exit()
。
frm_class frm = new frm_class();
frm.Show();
Application.Run();
// Some button or event inside the form should be executing the exit call:
Application.Exit();