基本信息
源码名称:备忘录
源码大小:0.05M
文件格式:.zip
开发语言:C#
更新时间:2018-07-19
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍
备忘录



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;


namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {

        public static string txtpath;
       
        public Form1()
        {
            InitializeComponent();


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.Sorted = false;
            //if (openFileDialog1.ShowDialog() == DialogResult.OK)
            //{
            //    txtPath = openFileDialog1.FileName;
            //}
            //else
            //{
            //    this.Close();
            //}
            //rd(txtpath);

            string txtPath = "C:/.......";
            //path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
            txtPath = txtPath "20180619Log.txt";
            ReadTxtToLst(listBox1,txtPath);
          
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
           
        }


        private void TestLog(string msg)
        {
            //string path = "C:/.......";
            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            string path = "C:/.......";
            //path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
            path = path "20180619Log.txt";
            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            //if (File.Exists(Server.MapPath("~/upimg/Data.html")))
            //{
            //    Response.Write("Yes");

            //    //存在文件

            //}

            //else
            //{
            //    Response.Write("No");
            //    //不存在文件
            //    File.Create(MapPath("~/upimg/Data.html"));//创建该文件

            //}
           
            FileStream fs = new FileStream(path, FileMode.Append);
            StreamWriter sw = new StreamWriter(fs, Encoding.GetEncoding("GB2312"));
            //sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") "  " msg);
            sw.WriteLine(monthCalendar1.SelectionStart.ToString("yyyy-MM-dd") "  " msg);
            sw.Close();
            fs.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            TestLog(textBox1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {

           
            listBox1.Items.Clear();
            //string path = "C:/.......";
            //path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
            //string path="";
            //path = path Form1.d;
            //MessageBox.Show("sadsa", path);
            //StreamReader sr = new StreamReader(path); //path是要读取的文件的完整路径
            //String str_read = sr.ReadToEnd(); //从开始到末尾读取文件的所有内容,str_read 存放的就是读取到的文本
            //sr.Close();
            //string[] arr = str_read.Split('\n');
            //foreach (string i in arr)
            // listBox1.Items.Add(i.ToString());
            //string[] strs = System.IO.File.ReadAllLines(path, System.Text.Encoding.Default);
            //foreach (string str in strs)
            //{
            //    listBox1.Items.Add(str.ToString());
            //}
            string path = "C:/.......";
            //path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
            path = path "20180619Log.txt";
         
            ReadTxtToLst(listBox1, path);
        
        
        }

        private void listBox1_DragLeave(object sender, EventArgs e)
        {
            
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            listBox1.Sorted = false;
            string path = "C:/.......";
            //path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
            path = path "20180619Log.txt";
            int m = listBox1.SelectedIndex;
            MessageBox.Show("", m.ToString());
            listBox1.Items.Remove(listBox1.SelectedItem);
           // DLst(path);
            var strs = System.IO.File.ReadAllLines(path, Encoding.Default).ToList();
            strs.RemoveAt(m);//删除第0行
            System.IO.File.WriteAllLines(path, strs, Encoding.Default);
           
           
        }

        private void WriteLstToTxt(ListBox lst, string spath) //listbox 写入txt文件
        {
           
            int count = lst.Items.Count;
            StreamWriter _wstream = new StreamWriter(spath);
            for (int i = 0; i < count; i )
            {
                string data = lst.Items[i].ToString();
                _wstream.Write(data);
                _wstream.WriteLine();
            }
           _wstream.Flush();
            _wstream.Close();
        }

        private void ReadTxtToLst(ListBox lst, string spath) //listbox 读取txt文件
        {
            StreamReader _rstream = new StreamReader(spath, System.Text.Encoding.Default);
            string line;
            while ((line = _rstream.ReadLine()) != null)
            {
                lst.Items.Add(line);
            }
            _rstream.Close();
        }

        private void DLst(string spath) //txt清除
        {
            System.IO.File.WriteAllText(spath, string.Empty);
        }

        private void button3_Click(object sender, EventArgs e)//写入txt文件
        {
            string path = "C:/.......";
            path = path DateTime.Today.ToString("yyyyMMdd") "Log.txt";
           WriteLstToTxt(listBox1, path);
        }

        public void  rd(string spath)
        {
            string d;
            d = spath;
        
        }

        public static string d { get; set; }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
            listBox1.SelectedItem = textBox1.Text;
        }

        private void listBox1_Click(object sender, EventArgs e)
        {
           
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click_1(object sender, EventArgs e)
        {

            string path = "C:/.......";
            path = path "20180619Log.txt";
            if (listBox1.Sorted == true)
            {
                listBox1.Sorted = false;
                listBox1.Items.Clear();
                ReadTxtToLst(listBox1, path);
                //(1)button1.PerformClick();按钮调用方法
                //(2)button1_Click(null,null);
                //(3)button_Click(null,new EventArgs());

            }
            else {
                listBox1.Sorted = true;
            }
        }

     

        
       

       

      

       
    }


}


.
├── WindowsFormsApplication6
│   ├── Form1.Designer.cs
│   ├── Form1.cs
│   ├── Form1.resx
│   ├── Program.cs
│   ├── Properties
│   │   ├── AssemblyInfo.cs
│   │   ├── Resources.Designer.cs
│   │   ├── Resources.resx
│   │   ├── Settings.Designer.cs
│   │   └── Settings.settings
│   ├── WindowsFormsApplication6.csproj
│   ├── bin
│   │   └── Debug
│   │       ├── WindowsFormsApplication6.exe
│   │       ├── WindowsFormsApplication6.pdb
│   │       ├── WindowsFormsApplication6.vshost.exe
│   │       └── WindowsFormsApplication6.vshost.exe.manifest
│   └── obj
│       └── x86
│           └── Debug
│               ├── DesignTimeResolveAssemblyReferences.cache
│               ├── DesignTimeResolveAssemblyReferencesInput.cache
│               ├── TempPE
│               ├── WindowsFormsApplication6.Form1.resources
│               ├── WindowsFormsApplication6.Properties.Resources.resources
│               ├── WindowsFormsApplication6.csproj.FileListAbsolute.txt
│               ├── WindowsFormsApplication6.csproj.GenerateResource.Cache
│               ├── WindowsFormsApplication6.csprojResolveAssemblyReference.cache
│               ├── WindowsFormsApplication6.exe
│               └── WindowsFormsApplication6.pdb
├── WindowsFormsApplication6.sln
└── 好例子网_WindowsFormsApplication6.zip

8 directories, 25 files