我最近一直在研究Android,並試圖將其功能之一移植到C#Compact Framework。試圖在下一個關閉窗體後顯示在C#cf
我所做的是創建一個抽象類,我稱其爲Activity。 這個類看起來像這樣
internal abstract class Activity
{
protected Form myForm;
private static Activity myCurrentActivity = null;
private static Activity myNextActivity = null;
internal static void LoadNext(Activity nextActivity)
{
myNextActivity = nextActivity;
if (myNextActivity != null)
{
myNextActivity.Show();
if (myCurrentActivity != null)
{
myCurrentActivity.Close();
myCurrentActivity = null;
}
myCurrentActivity = myNextActivity;
myNextActivity = null;
}
}
internal void Show()
{
//PROBLEM IS HERE
Application.Run(myForm);
//myForm.Show();
//myForm.ShowDialog();
//
}
internal void Close()
{
myForm.Close();
}
internal void GenerateForm()
{
///Code that uses the Layout class to create a form, and then stores it in myForm
//then attaches click handlers on all the clickable controls in the form
//it is besides the point in this problem
}
protected abstract void Click(Control control);
//this receives all the click events from all the controls in the form
//it is besides the point in this problem
}
我的問題是與運行Show()
命令
基本上所有我的類實現上面的類的一部分,加載XML文件並顯示它。 當我想過渡到一個新的類/形式(例如去從ACMain到ACLogIn) 我使用此代碼
Activity.LoadNext(new ACLogIn);
這是應該載入一個表格,顯示它和卸載當前表單
我曾嘗試這些解決方案(在Show()
方法),這裏是用myForm.ShowDialog()
每一個
問題0該工作,但塊執行的,這意味着舊的形式不緊密,並且更我的表單之間移動使用
myForm.Show()
這工作越進程堆棧增加,關閉之後的舊錶舊的顯示,但關閉的程序和終止後立即使用
Application.Run(myForm)
這僅適用第一種形式的加載,當我移動到下一個形式,它顯示那麼它拋出一個異常說「價值不在預期範圍內「
有人可以幫我解決這個問題或找到替代方案嗎?
主要問題是您只能有1個主窗體。看看Aplication是否有可寫的MainForm屬性,然後用Show()來使用它。 –