吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6812|回复: 45
收起左侧

[原创工具] C#创建新文件工具【开源】

  [复制链接]
XhyEax 发表于 2015-8-7 19:57
本帖最后由 XhyEax 于 2015-8-7 19:59 编辑

前言:因为对资源管理器的右键 新建的经常性的点击失误,所以,有了这个软件。(好吧,真相是手残)
简介:在程序运行目录新建文件,并进行读取写入操作(以系统默认编码)和运行操作(比如bat),拓展名默认设置为txt,bat,png,zip,7z(当然,你可以自己修改)
截图:
XhyEax  截图20150807194350.jpg

下载链接:
成品下载(免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);
            }
        }

             
    }
}




免费评分

参与人数 7威望 +1 热心值 +7 收起 理由
lldd + 1 我很赞同!
1101233873 + 1 我很赞同!
雷霆 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩.
叠噢 + 1 不评分就浪费了
lengyue52pojie + 1 谢谢@Thanks!
jzy937236161 + 1 H大都评了怎么敢不评
Hmily + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩.

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| XhyEax 发表于 2015-8-7 19:58
二楼自己的,待编辑。
头像被屏蔽
崽崽呦 发表于 2015-8-7 20:41
头像被屏蔽
崽崽呦 发表于 2015-8-7 20:16
jzy937236161 发表于 2015-8-7 20:17
楼主C语言有没有基础教程?
 楼主| XhyEax 发表于 2015-8-7 20:20
jzy937236161 发表于 2015-8-7 20:17
楼主C语言有没有基础教程?

额,层主你这算是乱入吗?C语基础教程我没有哦,你可以论坛搜索一下。
蓝色恋人 发表于 2015-8-7 20:21
不懂语言,还是支持下
 楼主| XhyEax 发表于 2015-8-7 20:21
崽崽呦 发表于 2015-8-7 20:16
前排        瞧瞧啦

层主,伪原创你还不承认吗?
头像被屏蔽
崽崽呦 发表于 2015-8-7 20:23
提示: 作者被禁止或删除 内容自动屏蔽
 楼主| XhyEax 发表于 2015-8-7 20:25

那个计算器啊,原作者说不是他发的
头像被屏蔽
崽崽呦 发表于 2015-8-7 20:26
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 提醒:禁止复制他人回复等『恶意灌水』行为,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-5 00:41

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表