c#使用对话框打开文件时出现问题

来源:百度知道 编辑:UC知道 时间:2024/05/06 01:39:31
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 档案管理系统
{
public partial class Form1 : Form
{
FileDialog oneFileDialog1 = new OpenFileDialog();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StreamWriter output=new StreamWriter (File.Open("D:\\my.csy",FileMode.Create));
output .Write(textBox1 .Text);
output.Close();
this.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
FileDialog oneFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:

你这个openFileDialog不是你拖进去的。vs没有给你自动添加事件。
你要在构造函数里面给它加上事件。
oneFileDialog1.FileOk +=new CancelEventHandler(openFileDialog1_FileOk);

判断oneBinaryReader.PeekChar() == -1 就是到文件尾啦。返回-1不是0

设置断点自己调试!