'Random_Number_File_Writer.Form1' 不包含'saveFileDialog1_FileOk' 的定义,并且找不到接受'Random_Number_File_Writer.Form1' 类型的第一个参数的扩展方法'saveFileDialog1)_FileOk'(您是否缺少 using 指令或程序集引用?)
那是我收到的错误消息。我试图去我大学的实验室寻求帮助,但那个人不熟悉 C#,我们花了大约一个小时才让我的行号显示出来(仅供参考......)然后我去找我的教授,他说他会忙一段时间。所以我想我会在这里尝试作为替代的帮助来源。
我查看了这里已经存在的关于类似错误的问题,但它仍然让我感到困惑,尤其是如何更正这个错误,并且当我尽可能接近地引用教科书中的代码时,我不确定我是否理解为什么我我什至得到这个错误。
这是代码,如果难以阅读,我很抱歉。哦,我知道这是产生错误的部分,因为我昨天运行它,没有这部分。但部分任务是保存为对话框。
try
{
//Initial opening point for save file dialogue
saveFileDialog1.InitialDirectory = @"C:\Users\Heather\Documents\Visual Studio 2010\Projects\Random Number File Writer";
//Save As popup - Opening the file for writing usage once it's created.
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
randomNumberFile = File.CreateText(openFileDialog1.FileName);
}
else // Popup informing user that the data will not save to a file because they didn't save.
{
MessageBox.Show("You elected not to save your data.");
}
这是未格式化的使用内容:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; // Added to be able to use StreamWriter variable type
这是我双击时它给出的代码片段,它将我带到 Form1.Designer.CS 窗口。
this.saveFileDialog1.FileOk += new System.ComponentModel.CancelEventHandler(this.saveFileDialog1_FileOk);