我想產生一個無模式對話框,每當我關閉對話框,並要打開它再次我收到一個錯誤說越來越System.ObjectDisposedException:無法訪問已釋放object.Modeless對話框在C#
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'TransactionHistoryDialog'.
at System.Windows.Forms.Control.CreateHandle()
這是我在每當transactionHistory按鈕被點擊我的主要形式,創建無模式對話框
public partial class TransactionHistoryDialog : Form
{
private static TransactionHistoryDialog instance;
private TransactionHistoryDialog()
{
InitializeComponent();
}
public static TransactionHistoryDialog CreateForm()
{
if (instance == null)
{
instance = new TransactionHistoryDialog();
}
return instance;
}
private void TransactionHistoryDialog_FormClosing(object sender, FormClosingEventArgs e)
{
instance = null;
}
private void buttonClose_Click(object sender, EventArgs e)
{
instance = null;
}
private void buttonTransactionHistoryClose_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
然後代碼交易的對話框顯示出來:這裏是我的點擊交易按鈕
的事件代碼3210private void buttonTransferHistory_Click(object sender, EventArgs e)
{
TransactionHistoryDialog transactionHistory = TransactionHistoryDialog.CreateForm();
transactionHistory.updateTextBox();
transactionHistory.Show();
}
我搜索了很多,但找不到問題所在。任何人都可以給我一些提示嗎?
你爲什麼要調用'this.Dispose();'?你不需要這樣做來關閉表單。 – Szymon