找感觉的第一个小程序

         将近一个季度没有接触.NET了,现在接触,感觉心里还是有点模糊,不知道如何下手;许多东西貌似都快忘记了,趁着下午没有事写了会程序,原本很多东西都忘记了,但是在写程序的过程中,我重拾了那些遗忘的,虽然速度没有以前那样,但是,我坚信没有什么做不到,只要我坚持;现在,也是该收心的时候了,我不能再那样模糊的生活着,我想要什么,那么我就要努力去实现,而不是这样的消极的过着;我必须重拾以前的自己,每天都有自己的目标,都是过得那样的充实;反观现在的自己,没有任何的生活目标,貌似一味的逃避,消极的过着每一天,这和以前的自己差别太大了,加油!

    下午写了会下程序,实现的功能主要有:创建文件夹、读取数据、读取文件夹得名称等操作,这在以前都做过,只是时间久了,许多东西都不是太清楚了;所以,就先从简单的复习,一步一个阶梯;如下实现的代码:

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;
using System.Net;




namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.skinEngine1.SkinFile = "Vista2_color2.ssk";///设置窗体的皮肤效果
             ///设置文件框的背景色彩;
            this.richTextBox1.BackColor = System.Drawing.Color.Aqua;

 }
         /// <summary>
        /// 该方法主要是用来打开文件对话框,并且获取数据。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_OpenFile_Click(object sender, EventArgs e)
        {
            string path = "";///路径.
            OpenFileDialog opd = new OpenFileDialog();
           ///判断是否选择了
            if(opd.ShowDialog()!=DialogResult.OK){///没有选择.


                return;
           }
            path = opd.FileName;///获取选中文件的路径;
                                 ///下面获取最后一个文件名
                                 ///
            string filename = path.Substring(path.LastIndexOf('\\')+1);
            MessageBox.Show(filename, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        }
        /// <summary>
        /// 关闭窗体操作;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Close_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("确定要退出该系统吗?","友情提醒",MessageBoxButtons.YesNo,MessageBoxIcon.Question)!=DialogResult.Yes){
                ///不退出操作,系统继续运行.
                return;            
            }
            this.Close();///退出操作.
     
        }


        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog opd = new OpenFileDialog();
            if(opd.ShowDialog()!=DialogResult.OK){///没有选择数据操作;
                MessageBox.Show("没有数据","提示操作");
                return;///返回,不读取任何数据.          
            }
            string path = opd.FileName;
            ///下面的操作时打开文件里面的数据。
            this.richTextBox1.LoadFile(path, RichTextBoxStreamType.PlainText);
        }
        /// <summary>
        /// 创建文件夹操作.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>


        private void Btn_CreateFile_Click(object sender, EventArgs e)
        {
            string files = this.richTextBox1.Text;///获取文件名
             if(files==""){
                 MessageBox.Show("请输入文件名","提示操作",MessageBoxButtons.OK,MessageBoxIcon.Stop);
                 return; 
             }
            ///提示用户选择文件夹操作;
             FolderBrowserDialog fbd = new FolderBrowserDialog();
                if(fbd.ShowDialog()!=DialogResult.OK){///没有选择;
                    return;        
                }   
            ///或许选取的文件路径
                string filepath = fbd.SelectedPath;
                MessageBox.Show(filepath,"提示");
            ///下面的操作时读取文件夹的名称.
                string filename = filepath.Substring(filepath.LastIndexOf('\\') + 1); 
            ///创建文件夹操作
            ///
            string  path=filepath+@"\"+files;
                if (Directory.Exists(path)) {
                    MessageBox.Show("该文件夹已经存在!","提示");
                    return;
                       }
               ///创建文件
                Directory.CreateDirectory(path);
                MessageBox.Show("创建成功!","提示");

        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值