当前位置: 首页>>代码示例>>C#>>正文


C# MonthCalendar.DateChanged事件代码示例

本文整理汇总了C#中System.Windows.Forms.MonthCalendar.DateChanged事件的典型用法代码示例。如果您正苦于以下问题:C# MonthCalendar.DateChanged事件的具体用法?C# MonthCalendar.DateChanged怎么用?C# MonthCalendar.DateChanged使用的例子?那么恭喜您, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在System.Windows.Forms.MonthCalendar的用法示例。


在下文中一共展示了MonthCalendar.DateChanged事件的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button1_Click

private void button1_Click(object sender, System.EventArgs e)
{
   // Create a SelectionRange object and set its Start and End properties.
   SelectionRange sr = new SelectionRange();
   sr.Start = DateTime.Parse(this.textBox1.Text);
   sr.End = DateTime.Parse(this.textBox2.Text);
   /* Assign the SelectionRange object to the 
      SelectionRange property of the MonthCalendar control. */
   this.monthCalendar1.SelectionRange = sr;
}

private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
   /* Display the Start and End property values of 
      the SelectionRange object in the text boxes. */
   this.textBox1.Text = 
     monthCalendar1.SelectionRange.Start.Date.ToShortDateString();
   this.textBox2.Text = 
     monthCalendar1.SelectionRange.End.Date.ToShortDateString();
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:20,代码来源:MonthCalendar.DateChanged

示例2: Main

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;

public class Form1 : System.Windows.Forms.Form
{
    private System.Windows.Forms.MonthCalendar monthCalendar1;
    private System.Windows.Forms.TextBox textBox1;

    [STAThread]
    static void Main() 
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
        this.textBox1.Location = new System.Drawing.Point(48, 488);
        this.textBox1.Multiline = true;
        this.textBox1.ReadOnly = true;
        this.textBox1.Size = new System.Drawing.Size(824, 32);

        // Create the calendar.
        this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();

        // Set the calendar location.
        this.monthCalendar1.Location = new System.Drawing.Point(47, 16);

        // Change the color.
        this.monthCalendar1.BackColor = System.Drawing.SystemColors.Info;
        this.monthCalendar1.ForeColor = System.Drawing.Color.FromArgb(
                                 ((System.Byte)(192)), ((System.Byte)(0)), ((System.Byte)(192)));
        this.monthCalendar1.TitleBackColor = System.Drawing.Color.Purple;
        this.monthCalendar1.TitleForeColor = System.Drawing.Color.Yellow;
        this.monthCalendar1.TrailingForeColor = System.Drawing.Color.FromArgb(
                                 ((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(0)));

        // Add dates to the AnnuallyBoldedDates array.
        this.monthCalendar1.AnnuallyBoldedDates = 
            new System.DateTime[] { new System.DateTime(2002, 4, 20, 0, 0, 0, 0),
                                    new System.DateTime(2002, 4, 28, 0, 0, 0, 0),
                                    new System.DateTime(2002, 5, 5, 0, 0, 0, 0),
                                    new System.DateTime(2002, 7, 4, 0, 0, 0, 0),
                                    new System.DateTime(2002, 12, 15, 0, 0, 0, 0),
                                    new System.DateTime(2002, 12, 18, 0, 0, 0, 0)};

        // Add dates to BoldedDates array.
        this.monthCalendar1.BoldedDates = new System.DateTime[] {new System.DateTime(2002, 9, 26, 0, 0, 0, 0)};

        // Add dates to MonthlyBoldedDates array.
        this.monthCalendar1.MonthlyBoldedDates = 
           new System.DateTime[] {new System.DateTime(2002, 1, 15, 0, 0, 0, 0),
                                  new System.DateTime(2002, 1, 30, 0, 0, 0, 0)};

        // Configure the calendar to display 3 rows by 4 columns of months.
        this.monthCalendar1.CalendarDimensions = new System.Drawing.Size(4, 3);

        // Set week to begin on Monday.
        this.monthCalendar1.FirstDayOfWeek = System.Windows.Forms.Day.Monday;

        // Set the maximum visible date on the calendar to 12/31/2010.
        this.monthCalendar1.MaxDate = new System.DateTime(2010, 12, 31, 0, 0, 0, 0);

        // Set the minimum visible date on calendar to 12/31/2010.
        this.monthCalendar1.MinDate = new System.DateTime(1999, 1, 1, 0, 0, 0, 0);

        // Only allow 21 days to be selected at the same time.
        this.monthCalendar1.MaxSelectionCount = 21;

        // Set the calendar to move one month at a time when navigating using the arrows.
        this.monthCalendar1.ScrollChange = 1;

        // Do not show the "Today" banner.
        this.monthCalendar1.ShowToday = false;

        // Do not circle today's date.
        this.monthCalendar1.ShowTodayCircle = false;
            
        // Show the week numbers to the left of each week.
        this.monthCalendar1.ShowWeekNumbers = true;

        // Add event handlers for the DateSelected and DateChanged events
        this.monthCalendar1.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateSelected);
        this.monthCalendar1.DateChanged += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar1_DateChanged);

        // Set up how the form should be displayed and add the controls to the form.
        this.ClientSize = new System.Drawing.Size(920, 566);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {this.textBox1, this.monthCalendar1});
        this.Text = "Month Calendar Example";
    }

    private void monthCalendar1_DateSelected(object sender, System.Windows.Forms.DateRangeEventArgs e)
    {
        // Show the start and end dates in the text box.
        this.textBox1.Text = "Date Selected: Start = " +
            e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
    }

    private void monthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
    {
        // Show the start and end dates in the text box.
        this.textBox1.Text = "Date Changed: Start =  " +
            e.Start.ToShortDateString() + " : End = " + e.End.ToShortDateString();
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:108,代码来源:MonthCalendar.DateChanged

示例3: Calendar

//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;

public class Calendar : Form
{
  MonthCalendar mc;
  DateTimePicker dtpStart;    
  DateTimePicker dtpEnd;    
  DateTimePicker dtpBold;    
  Label lblStart;
  Label lblEnd;
  Label lblStartDay;
  Label lblBold;
  ComboBox cmbStart;
  Button btnBoldDay;
  Button btnBoldMonthly;
  Button btnBoldAnnually;

  public Calendar()
  {
    Size = new Size(650,450);
    this.Load += new EventHandler(this_Load);

    mc = new MonthCalendar();
    mc.Parent = this;
    mc.Location = new Point(20,20);
    mc.Font = new Font("Times New Roman", 14);
    mc.CalendarDimensions = new Size(2,1);
    mc.FirstDayOfWeek = Day.Monday;
    mc.MaxSelectionCount = 45;
    mc.DateChanged += new DateRangeEventHandler(mc_DateChanged);
    mc.DateSelected += new DateRangeEventHandler(mc_DateSelected);

    lblStart = new Label();
    lblStart.Parent = this;
    lblStart.Text = "Start Date:";
    
    dtpStart = new DateTimePicker();
    dtpStart.Parent = this;
    dtpStart.Size = new Size((int)(Font.Height * .6) * 
              dtpStart.Value.ToString("D").Length,
              dtpStart.PreferredHeight);
    dtpStart.Format = DateTimePickerFormat.Long;
    dtpStart.ShowUpDown = true;
    dtpStart.ValueChanged += new EventHandler(dtpStart_ValueChanged);

    lblEnd = new Label();
    lblEnd.Parent = this;
    lblEnd.Text = "End Date:";
    
    dtpEnd = new DateTimePicker();
    dtpEnd.Parent = this;
    dtpEnd.Size = new Size((int)(Font.Height * .6) * 
              dtpEnd.Value.ToString("D").Length,
              dtpEnd.PreferredHeight);
    dtpEnd.Format = DateTimePickerFormat.Long;
    dtpEnd.ShowUpDown = true;
    dtpEnd.ValueChanged += new EventHandler(dtpEnd_ValueChanged);
        
    lblStartDay = new Label();
    lblStartDay.Parent = this;
    lblStartDay.Text = "Start Day:";
    
    cmbStart = new ComboBox();
    cmbStart.Parent = this;
    cmbStart.DropDownStyle = ComboBoxStyle.DropDownList;
    cmbStart.Items.AddRange(new object[] {"Monday", 
                      "Tuesday", 
                      "Wednesday", 
                      "Thursday", 
                      "Friday", 
                      "Saturday", 
                      "Sunday"});
    cmbStart.SelectedIndex = 0;
    cmbStart.SelectedIndexChanged += new EventHandler(cmbStart_SelectedIndexChanged);
    
    lblBold = new Label();
    lblBold.Parent = this;
    lblBold.Text = "Bold Day:";
    
    dtpBold = new DateTimePicker();
    dtpBold.Parent = this;
    dtpBold.Size = new Size((int)(Font.Height ) * 
              dtpBold.Value.ToString("d").Length,
              dtpBold.PreferredHeight);
    dtpBold.Format = DateTimePickerFormat.Short;
    dtpBold.ShowUpDown = true;
    
    btnBoldDay = new Button();
    btnBoldDay.Parent = this;
    btnBoldDay.Text = "Add Bold Day";
    btnBoldDay.Size = new Size((int)(Font.Height * .6) * 
                btnBoldDay.Text.Length,
                (int)(Font.Height * 1.75));
    btnBoldDay.Click += new EventHandler(btnBoldDay_Click);
    
    btnBoldMonthly = new Button();
    btnBoldMonthly.Parent = this;
    btnBoldMonthly.Text = "Add Bold Day Monthly";
    btnBoldMonthly.Size = new Size((int)(Font.Height * .6) * 
                  btnBoldMonthly.Text.Length,
                  (int)(Font.Height * 1.75));
    btnBoldMonthly.Click += new EventHandler(btnBoldMonthly_Click);

    btnBoldAnnually = new Button();
    btnBoldAnnually.Parent = this;
    btnBoldAnnually.Text = "Add Bold Day Annually";
    btnBoldAnnually.Size = new Size((int)(Font.Height * .6) * 
                    btnBoldAnnually.Text.Length,
                    (int)(Font.Height * 1.75));
    btnBoldAnnually.Click += new EventHandler(btnBoldAnnually_Click);
  }

  static void Main() 
  {
    Application.Run(new Calendar());
  }

  private void this_Load(object sender, EventArgs e)
  {
    lblStart.Location = new Point(mc.Left, mc.Bottom + 10);
    dtpStart.Location = new Point(lblStart.Right, mc.Bottom + 10);

    lblEnd.Location = new Point(mc.Left, lblStart.Bottom + 5);
    dtpEnd.Location = new Point(lblStart.Right, lblStart.Bottom + 5);
    
    lblStartDay.Location = new Point(mc.Left, lblEnd.Bottom + 5);
    cmbStart.Location = new Point(lblStart.Right, lblEnd.Bottom + 5);

    lblBold.Location = new Point(mc.Left, lblStartDay.Bottom + 5);
    dtpBold.Location = new Point(lblBold.Right, 
                  lblStartDay.Bottom + 5);
    
    btnBoldDay.Location = new Point(dtpBold.Right + 10, dtpBold.Top);
    btnBoldMonthly.Location = new Point(btnBoldDay.Right, 
                      dtpBold.Top);
    btnBoldAnnually.Location = new Point(btnBoldMonthly.Right, 
                      dtpBold.Top);
  }

  private void dtpStart_ValueChanged(object sender, EventArgs e)
  {
    mc.SelectionStart = dtpStart.Value;
  }    

  private void dtpEnd_ValueChanged(object sender, EventArgs e)
  {
    mc.SelectionEnd = dtpEnd.Value;
  }    

  private void mc_DateChanged(object sender, DateRangeEventArgs e)
  {
    MessageBox.Show("DateChanged");
    dtpStart.Value = e.Start;
    dtpEnd.Value = e.End;
  }

  private void mc_DateSelected(object sender, DateRangeEventArgs e)
  {
    MessageBox.Show("DateSelected");
  }

  private void cmbStart_SelectedIndexChanged(object sender, 
                        EventArgs e)
  {
    mc.FirstDayOfWeek = (Day)cmbStart.SelectedIndex;
  }

  private void btnBoldDay_Click(object sender, EventArgs e)
  {
    mc.AddBoldedDate(dtpBold.Value);
    mc.UpdateBoldedDates();
  }

  private void btnBoldMonthly_Click(object sender, EventArgs e)
  {
    mc.AddMonthlyBoldedDate(dtpBold.Value);
    mc.UpdateBoldedDates();
  }

  private void btnBoldAnnually_Click(object sender, EventArgs e)
  {
    mc.AddAnnuallyBoldedDate(dtpBold.Value);
    mc.UpdateBoldedDates();
  }
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:188,代码来源:MonthCalendar.DateChanged


注:本文中的System.Windows.Forms.MonthCalendar.DateChanged事件示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。