求帮助|openFileDialog1 点南button1没反应

.Net技术 码拜 7年前 (2017-04-26) 961次浏览
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;
namespace TXT转Unicode
{
public partial class Frm_Main : Form
{
public Frm_Main()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.Filter = “txt文件(*.txt)|*.txt”;//筛选文件
if (this.openFileDialog1.ShowDialog(this) == DialogResult.OK)//弹出打开文件对话框
{
System.IO.StreamReader sr = new//创建文件读取器对象
System.IO.StreamReader(openFileDialog1.FileName, Encoding.Default);
textBox1.Text = sr.ReadToEnd();//显示文本文件内容
sr.Close();//关闭流
}
}
}
}
本人是照着书上写的,也没什么警告和错误,但是编译后点击button1没反应,也不弹出打开文件的对话框。
解决方案

40

你没有把button1的Click事件和button1_Click关联起来
要么手工写  要么直接在设计器里选择button1 在属性-事件里面选Click  选择button1_Click

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明求帮助|openFileDialog1 点南button1没反应
喜欢 (0)
[1034331897@qq.com]
分享 (0)