如何实现点击textbox显示monthCalendar 选择monthCalendar把值传给textbox

C# code
private void textBox1_MouseDown(object sender, MouseEventArgs e) { MonthCalendar ms = new MonthCalendar(); this.Controls.Add(ms); ms.DateChanged += new DateRangeEventHandler(ms_DateChanged); } void ms_DateChanged(object sender, DateRangeEventArgs e) { this.textBox1.Text = e.Start.Date.ToString(); }

private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            monthCalendar1.Visible = true;
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
           textBox1.Text= monthCalendar1.SelectionStart.ToString();
           monthCalendar1.Visible = false;
        } 
这个是不可以复制的,你要找到那个事件才得啊,你单击monthCalendar1控件,在它的事件那里找到DateSelected双击它,然后就出来private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        { } 这个东西,你就在里面加textBox1.Text= monthCalendar1.SelectionStart.ToString();
           monthCalendar1.Visible = false;

 

事件请自己在属性那栏里添加啦!!

测试可以实现你说的功能啊

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

namespace 日期控件
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_MouseClick(object sender, MouseEventArgs e)
        {
            if (this.monthCalendar1.Visible == false)
            { this.monthCalendar1.Visible = true; }
            else
            {

                this.monthCalendar1.Visible = false;
            }
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            string DateTime=this.monthCalendar1.SelectionStart.ToString();
            this.textBox1.Text = DateTime;
            this.monthCalendar1.Visible = false;
        }
    }
} 

 

 

posted on 2012-04-13 17:21 SkyDream 阅读(8124) 评论(0)  编辑  收藏 所属分类: C# WinForm

<2012年4月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜