有一个BUTTON,点击后出现MonthCalendar,选择日期后MonthCalendar自动消失.这个怎么做?
谢谢大家了

解决方案 »

  1.   

    建议使用 DateTimePicker 控件。
      

  2.   

    using System;
    using System.Windows.Forms;class Test : Form
    {
      DateDialog dd  = new DateDialog();
      Label      lbl =  new Label();  Test()
      {
        Button btn = new Button();
        btn.Parent = this;
        btn.Text   = "选择日期";
        btn.Top    = 30;
        btn.Click += new EventHandler(SelectDate);    lbl.Parent = this;
        lbl.AutoSize = true;
      }  void SelectDate(object sender, EventArgs e)
      {
        dd.ShowDialog();
        lbl.Text = "您选择的日期是: " + dd.mc.SelectionStart.ToString("yyyy.MM.dd");
      }  static void Main()
      {
        Application.Run(new Test());
      }
    }class DateDialog : Form
    {
      public MonthCalendar mc;  public DateDialog()
      {
        FormBorderStyle  = FormBorderStyle.FixedSingle;
        MaximizeBox      = false;
        MinimizeBox      = false;
        ShowInTaskbar    = false;
        Width            = 275;
        Height           = 170;    mc               = new MonthCalendar();
        mc.Parent        = this;
        mc.DateSelected += new DateRangeEventHandler(DateSelect);
      }  void DateSelect(object sender, DateRangeEventArgs e)
      {
        DialogResult = DialogResult.OK;
      }
    }