本帖最后由 XhyEax 于 2015-8-7 19:59 编辑
前言:因为对资源管理器的右键 新建的经常性的点击失误,所以,有了这个软件。(好吧,真相是手残)
简介:在程序运行目录新建文件,并进行读取写入操作(以系统默认编码)和运行操作(比如bat),拓展名默认设置为txt,bat,png,zip,7z(当然,你可以自己修改)
截图:
下载链接:
成品下载(免CB): http://pan.baidu.com/s/1o602L2y
解决方案(成品+源码):
CreatNewFile(All).zip
(98.37 KB, 下载次数: 7)
百度网盘地址(成品+源码)(回复可见):
链接: http://pan.baidu.com/s/1o6mVBWu 密码: qubg
源码(有点长,建议下载解决方案):
[C#] 纯文本查看 复制代码 using System;
using System.IO;
using System.Windows.Forms;
namespace CreatNewFile
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCreate_Click(object sender, EventArgs e)
{
string file = Application.StartupPath + "/" + textName.Text + "." + comboExtra.Text;
if (File.Exists(file))
{
if (MessageBox.Show("已存在该文件!是否继续新建?(这将清空原文件内容!)", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
FileStream newF = new FileStream(file, FileMode.Create);
newF.Close();
}
else
{
MessageBox.Show("已取消!");
}
}
else
{
FileStream newF = new FileStream(file, FileMode.Create);
newF.Close();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
string file = Application.StartupPath + "/" + textName.Text + "." + comboExtra.Text;
if (File.Exists(file))
{
btnWrite.Enabled = true;
btnRun.Enabled = true;
btnRead.Enabled = true;
}
else
{
btnWrite.Enabled = false;
btnRun.Enabled = false;
btnRead.Enabled = false;
}
}
private void btnWrite_Click(object sender, EventArgs e)
{
string txt = richTextInPut.Text;
string file = Application.StartupPath + "/" + textName.Text + "." + comboExtra.Text;
FileStream myFs = new FileStream(file, FileMode.Create);
StreamWriter mySw = new StreamWriter(myFs);
mySw.Write(txt);
mySw.Close();
myFs.Close();
MessageBox.Show("写入成功!");
}
private void button1_Click(object sender, EventArgs e)
{
string path = Application.StartupPath;
System.Diagnostics.Process.Start("explorer.exe", path);
}
private void btnRun_Click(object sender, EventArgs e)
{
string path = Application.StartupPath + "/" + textName.Text + "." + comboExtra.Text;
try
{
System.Diagnostics.Process.Start(path);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnRead_Click(object sender, EventArgs e)
{
try {
string path = Application.StartupPath + "/" + textName.Text + "." + comboExtra.Text;
StreamReader sr = new StreamReader(path, false);
richTextInPut.Text = sr.ReadToEnd().ToString();
sr.Close();
MessageBox.Show("读取成功!");
}
catch(Exception ex)
{
MessageBox.Show(""+ex);
}
}
}
}
|