/*
说明:三控件,button1 开始,button2 复制代码.txt_file(TextBox控件) 显示文件路径,另外一个TextBox 显示结果。有个openfiledialog打开文件。
*/
namespace 文件去除行号
{
public partial class Form1 : Form
{
bool isHasName = false; //是否有文件
string fileName = string.Empty; //文件名
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (DialogResult.OK == this.openFileDialog1.ShowDialog())
{
this.txt_File.Text = this.openFileDialog1.FileName;
ModifyFile(this.openFileDialog1.FileName);
}
}
public void ModifyFile(string fileName)
{
string message = string.Empty;
try
{
using (FileStream fs = new FileStream(@fileName, FileMode.Open, FileAccess.ReadWrite))
{
using (StreamReader sr = new StreamReader(fs))
{
this.textBox1.Text = "//转换过后的字符是" + Environment.NewLine + Regex.Replace(sr.ReadToEnd(), @"^\s*\d+", " ", RegexOptions.Multiline);
message = "转换成功";
}
}
}
catch (Exception ex)
{
message = ex.Message;
}
finally
{
MessageBox.Show(message);
}
}
private void button2_Click(object sender, EventArgs e)
{
//MemoryStream ms = new MemoryStream();
//this.textBox1.Save(ms, ImageFormat.Gif);
//Clipboard.SetData(DataFormats.Bitmap, ms);
//Image image = new Bitmap((MemoryStream)Clipboard.GetData(DataFormats.Bitmap));
//pictureBox2.Image = image;
//Clipboard.SetDataObject(Image.FromFile(openFileDialog1.FileName), false);
if (!string.IsNullOrEmpty(this.textBox1.Text))
{
Clipboard.SetText(this.textBox1.Text);
MessageBox.Show("复制成功!");
}
else
{
return;
}
}
}
}