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


namespace NO.心情随记
{
    public partial class Form1 : Form
    {
    
        public Form1()
        {
            InitializeComponent();
                      
            }

        private void button1_Click(object sender, EventArgs e)
        {
            
            
            using (StreamWriter sw = new StreamWriter(Application.StartupPath + @"\NoteBook.TXT", true, Encoding.Unicode))
            {

                sw.WriteLine(DateTime.Now + "  " + textBox1.Text);
            }
            textBox1.Text = "";
          
                label2.Text = "状态:"+DateTime.Now + "  记录成功";
 
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            if (File.Exists(Application.StartupPath + @"\NoteBook.TXT"))
            {
                System.Diagnostics.Process.Start(Application.StartupPath + @"\NoteBook.TXT");
            }
            else
            {
                label2.Text = "状态:" + DateTime.Now + "  文件不存在"; 
            }
            
            

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 27)
                this.Close();
            if (e.KeyChar == 13)
            {
                
                button1.PerformClick();
            
            }
        }
//------------------------------------------------------------------------------------
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                mouseOff = new Point(-e.X, -e.Y); //得到变量的值
                leftFlag = true;                  //点击左键按下时标注为true;
            
            }

        }

        Point mouseOff;//鼠标移动位置变量

        bool leftFlag;//标签是否为左键


        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                Point mouseSet = Control.MousePosition;
                mouseSet.Offset(mouseOff.X, mouseOff.Y);  //设置移动后的位置
                Location = mouseSet;
            }
        }


        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (leftFlag)
            {
                leftFlag = false;//释放鼠标后标注为false;
            }
        }

        private void label3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            textBox1.Focus();//在窗口显示时候,text获得焦点
        }


    }
}