超简单的wf日记程序

namespace MonthCalender
{
    public partial class Form1 : Form
    {
// 声明一个哈希表diary:键存放写日记的日期,值存放当天的日记内容
        private Hashtable diary = new Hashtable();
        public Form1()
        {
            InitializeComponent();
        }
//在日历控件日期改变时触发的DateChanged事件中写查看日记的代码
        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
               //如果哈希表的键集合diary.ContainsKey中包括日期日历控件选择的日期(哈希的键是日记的日期)monthCalendar1.SelectionStart的话,
            if (diary.ContainsKey(monthCalendar1.SelectionStart))
            {
                //利用哈希表值=哈希表对象[键]的方式把值取出来,赋给textbox
                textBox1.Text = diary[monthCalendar1.SelectionStart].ToString();
            }
            else
            {//如果选的那天没有值(日记)的话,就显示“没有记录”
                textBox1.Text = "没有记录";
            }
        }
//保存日记
        private void button1_Click(object sender, EventArgs e)
        {
            //如果选中的日期,原来就存在,把textbox1的内容再添加回去,也是有点像修改
            if (diary.ContainsKey(monthCalendar1.SelectionStart))
            {
               diary[monthCalendar1.SelectionStart] = textBox1.Text;
            }
            else//如果不存在,说明是新日记,就同时存入日历的选中日期为键,内容为值存到哈希对象diary中
            {
                diary.Add(monthCalendar1.SelectionStart,textBox1 .Text );
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }

你可能感兴趣的:(程序)