所以我一直在努力在我的.NET應用程序中創建一個「保存」按鈕。根據我的研究,我似乎正在做一切正確的事情。我已經提到這篇文章作爲主要來源:http://msdn.microsoft.com/en-us/library/system.windows.forms.savefiledialog.aspx在C#/ .NET中使用SaveFileDialog生成「無法創建抽象類的實例」錯誤
下面是在C#中我的方法的代碼:
private void save2(object A_0, EventArgs A_1)
{
Stream stream = new Stream();
savefile2 = new SaveFileDialog();
savefile2.InitialDirectory = @"C:\Program Files\Folder\";
savefile2.Filter = "Text files (*.txt)|*.txt|Word files (*.doc)|*.doc";
savefile2.FilterIndex = 1;
savefile2.FileName = "*.txt";
savefile2.Title = "Save Box Text";
savefile2.OverwritePrompt = true;
if (savefile2.ShowDialog() == DialogResult.OK)
{
stream = savefile2.OpenFile();
if (stream != null)
{
stream.Close();
}
}
}
運行程序時,我點擊「保存」按鈕,看它是否會打開一個對話框,它會產生以下錯誤:
「無法創建抽象類的實例。」
但是,我沒有使用任何抽象類。所有的類都在.NET框架中。所以,我卡住了。任何幫助,將不勝感激。