Hình mấu :
Click vào hình ảnh để lấy hình ảnh lớn

Tên:		calendar.png
Lần xem:	16
Size:		10.1 KB
ID:		5059

Source Code:

Visual C# Code:
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7.  
  8. namespace Calendar
  9. {
  10.     /// <summary>
  11.     /// Summary description for Calendar.
  12.     /// </summary>
  13.     public class Calendar : System.Windows.Forms.Form
  14.     {
  15.         private System.Windows.Forms.MonthCalendar monthCalendar1;
  16.         private System.Windows.Forms.Button button1;
  17.         /// <summary>
  18.         /// Required designer variable.
  19.         /// </summary>
  20.         private System.ComponentModel.Container components = null;
  21.  
  22.         public Calendar()
  23.         {
  24.             //
  25.             // Required for Windows Form Designer support
  26.             //
  27.             InitializeComponent();
  28.  
  29.             //
  30.             // TODO: Add any constructor code after InitializeComponent call
  31.             //
  32.         }
  33.  
  34.         /// <summary>
  35.         /// Clean up any resources being used.
  36.         /// </summary>
  37.         protected override void Dispose( bool disposing )
  38.         {
  39.             if( disposing )
  40.             {
  41.                 if (components != null)
  42.                 {
  43.                     components.Dispose();
  44.                 }
  45.             }
  46.             base.Dispose( disposing );
  47.         }
  48.  
  49.         #region Windows Form Designer generated code
  50.         /// <summary>
  51.         /// Required method for Designer support - do not modify
  52.         /// the contents of this method with the code editor.
  53.         /// </summary>
  54.         private void InitializeComponent()
  55.         {
  56.          this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
  57.          this.button1 = new System.Windows.Forms.Button();
  58.          this.SuspendLayout();
  59.          //
  60.          // monthCalendar1
  61.          //
  62.          this.monthCalendar1.FirstDayOfWeek = System.Windows.Forms.Day.Thursday;
  63.          this.monthCalendar1.Location = new System.Drawing.Point(16, 16);
  64.          this.monthCalendar1.Name = "monthCalendar1";
  65.          this.monthCalendar1.ShowTodayCircle = false;
  66.          this.monthCalendar1.ShowWeekNumbers = true;
  67.          this.monthCalendar1.TabIndex = 0;
  68.          //
  69.          // button1
  70.          //
  71.          this.button1.Location = new System.Drawing.Point(48, 184);
  72.          this.button1.Name = "button1";
  73.          this.button1.Size = new System.Drawing.Size(128, 23);
  74.          this.button1.TabIndex = 1;
  75.          this.button1.Text = "Selection Range";
  76.          this.button1.Click += new System.EventHandler(this.button1_Click_1);
  77.          //
  78.          // Calendar
  79.          //
  80.          this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  81.          this.ClientSize = new System.Drawing.Size(232, 213);
  82.          this.Controls.AddRange(new System.Windows.Forms.Control[] {
  83.                                                                       this.button1,
  84.                                                                       this.monthCalendar1});
  85.          this.Name = "Calendar";
  86.          this.Text = "Calendar Control";
  87.          this.Load += new System.EventHandler(this.Calendar_Load);
  88.          this.ResumeLayout(false);
  89.  
  90.       }
  91.         #endregion
  92.  
  93.         /// <summary>
  94.         /// The main entry point for the application.
  95.         /// </summary>
  96.         [STAThread]
  97.         static void Main()
  98.         {
  99.             Application.Run(new Calendar());
  100.         }
  101.  
  102.         private void Calendar_Load(object sender, System.EventArgs e)
  103.         {
  104.             string str = monthCalendar1.Text.ToString()  ;
  105.         }
  106.  
  107.         private void button1_Click(object sender, System.EventArgs e)
  108.         {
  109.         }
  110.  
  111.         private void button1_Click_1(object sender, System.EventArgs e)
  112.         {
  113.             // Get the selection Range.  
  114.             SelectionRange sr = monthCalendar1.SelectionRange;
  115.             // Get the start of Range.
  116.             DateTime st = sr.Start;
  117.             // Get the end of Range.
  118.             DateTime se = sr.End ;
  119.  
  120.             MessageBox.Show("RANGE START = " + st.ToString() + "\nRANGE END = " + se.ToString(), "Range Selection");
  121.    
  122.         }
  123.     }
  124. }