Từ 1 tới 2 trên tổng số 2 kết quả

Đề tài: Tạo Lịch (Calendar) trong lập trình C#

  1. #1
    Ngày gia nhập
    09 2006
    Nơi ở
    /usr/share/.hack@
    Bài viết
    1,433

    Smile Tạo Lịch (Calendar) trong lập trình C#

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

Tên:		lich.png
Lần xem:	68
Size:		17.5 KB
ID:		5058

    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.   public class CarConfigForm : System.Windows.Forms.Form
    9.   {
    10.     private System.Windows.Forms.ToolTip calendarTip;
    11.     private System.Windows.Forms.Label label5;
    12.     protected System.Windows.Forms.MonthCalendar monthCalendar;
    13.     private System.Windows.Forms.Label label3;
    14.     private System.Windows.Forms.Label label2;
    15.     private System.Windows.Forms.Label label1;
    16.     protected System.Windows.Forms.ComboBox comboSalesPerson;
    17.     protected System.Windows.Forms.ListBox carMakeList;
    18.     protected System.Windows.Forms.CheckedListBox checkedBoxRadioOptions;
    19.     protected System.Windows.Forms.Button btnOrder;
    20.     protected System.Windows.Forms.CheckBox checkFloorMats;
    21.     protected System.Windows.Forms.RadioButton radioPink;
    22.     protected System.Windows.Forms.RadioButton radioYellow;
    23.     protected System.Windows.Forms.RadioButton radioRed;
    24.     protected System.Windows.Forms.RadioButton radioGreen;
    25.     protected System.Windows.Forms.GroupBox groupBox1;
    26.  
    27.     public CarConfigForm()
    28.     {
    29.       InitializeComponent();
    30.       CenterToScreen();
    31.     }
    32.  
    33.     private void InitializeComponent()
    34.     {
    35.       this.comboSalesPerson = new System.Windows.Forms.ComboBox ();
    36.       this.radioRed = new System.Windows.Forms.RadioButton ();
    37.       this.groupBox1 = new System.Windows.Forms.GroupBox ();
    38.       this.radioPink = new System.Windows.Forms.RadioButton ();
    39.       this.monthCalendar = new System.Windows.Forms.MonthCalendar ();
    40.       this.checkedBoxRadioOptions = new System.Windows.Forms.CheckedListBox ();
    41.       this.calendarTip = new System.Windows.Forms.ToolTip (new System.ComponentModel.Container());
    42.       this.radioYellow = new System.Windows.Forms.RadioButton ();
    43.       this.label5 = new System.Windows.Forms.Label ();
    44.       this.carMakeList = new System.Windows.Forms.ListBox ();
    45.       this.radioGreen = new System.Windows.Forms.RadioButton ();
    46.       this.checkFloorMats = new System.Windows.Forms.CheckBox ();
    47.       this.label3 = new System.Windows.Forms.Label ();
    48.       this.btnOrder = new System.Windows.Forms.Button ();
    49.       this.label1 = new System.Windows.Forms.Label ();
    50.       this.label2 = new System.Windows.Forms.Label ();
    51.       comboSalesPerson.Location = new System.Drawing.Point (16, 80);
    52.       comboSalesPerson.Size = new System.Drawing.Size (128, 21);
    53.       comboSalesPerson.TabIndex = 1;
    54.       comboSalesPerson.Items.AddRange(new object[4] {"A", "B", "C", "D"});
    55.       radioRed.Location = new System.Drawing.Point (264, 24);
    56.       radioRed.Text = "Red";
    57.       radioRed.Size = new System.Drawing.Size (64, 23);
    58.       radioRed.TabIndex = 2;
    59.       radioRed.TabStop = true;
    60.       radioRed.BackColor = System.Drawing.SystemColors.ControlLight;
    61.       groupBox1.Location = new System.Drawing.Point (8, 120);
    62.       groupBox1.TabIndex = 4;
    63.       groupBox1.TabStop = false;
    64.       groupBox1.Text = "Exterior Color";
    65.       groupBox1.Size = new System.Drawing.Size (432, 56);
    66.       groupBox1.Leave += new System.EventHandler (this.groupBox1_Leave);
    67.       groupBox1.Enter += new System.EventHandler (this.groupBox1_Enter);
    68.       radioPink.Location = new System.Drawing.Point (176, 24);
    69.       radioPink.Text = "Pink";
    70.       radioPink.Size = new System.Drawing.Size (56, 23);
    71.       radioPink.TabIndex = 3;
    72.       radioPink.TabStop = true;
    73.       radioPink.BackColor = System.Drawing.SystemColors.ControlLight;
    74.  
    75.       monthCalendar.Location = new System.Drawing.Point (20, 224);
    76.       calendarTip.SetToolTip (monthCalendar, "Please select the date (or dates)");
    77.       monthCalendar.TabIndex = 10;
    78.       monthCalendar.TabStop = true;
    79.       checkedBoxRadioOptions.Location = new System.Drawing.Point (168, 32);
    80.       checkedBoxRadioOptions.Cursor = Cursors.Hand;
    81.       checkedBoxRadioOptions.Size = new System.Drawing.Size (152, 64);
    82.       checkedBoxRadioOptions.CheckOnClick = true;
    83.       checkedBoxRadioOptions.TabIndex = 2;
    84.       checkedBoxRadioOptions.Items.AddRange(new object[6] {"1", "2", "3", "4", "5", "6"});
    85.       calendarTip.Active = true;
    86.       radioYellow.Location = new System.Drawing.Point (96, 24);
    87.       radioYellow.Text = "Yellow";
    88.       radioYellow.Size = new System.Drawing.Size (56, 23);
    89.       radioYellow.TabIndex = 1;
    90.       radioYellow.TabStop = true;
    91.       radioYellow.BackColor = System.Drawing.SystemColors.ControlLight;
    92.       label5.Location = new System.Drawing.Point (20, 200);
    93.       label5.Text = "Delivery Date:";
    94.       label5.Size = new System.Drawing.Size (184, 16);
    95.       label5.Font = new System.Drawing.Font ("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Bold);
    96.       label5.TabIndex = 12;
    97.       carMakeList.Location = new System.Drawing.Point (328, 32);
    98.       carMakeList.Size = new System.Drawing.Size (112, 56);
    99.       carMakeList.ScrollAlwaysVisible = true;
    100.       carMakeList.TabIndex = 3;
    101.       carMakeList.Sorted = true;
    102.       carMakeList.Items.AddRange(new object[9] {"A", "B", "C", "D", "E", "F", "G", "H", "I"});
    103.       radioGreen.Location = new System.Drawing.Point (16, 24);
    104.       radioGreen.Text = "Green";
    105.       radioGreen.Size = new System.Drawing.Size (64, 23);
    106.       radioGreen.TabIndex = 0;
    107.       radioGreen.TabStop = true;
    108.       radioGreen.BackColor = System.Drawing.SystemColors.ControlLight;
    109.  
    110.       checkFloorMats.Location = new System.Drawing.Point (16, 16);
    111.       checkFloorMats.Text = "Extra Floor Mats";
    112.       checkFloorMats.Size = new System.Drawing.Size (112, 24);
    113.       checkFloorMats.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
    114.       checkFloorMats.TabIndex = 0;
    115.       label3.Location = new System.Drawing.Point (328, 8);
    116.       label3.Text = "Make:";
    117.       label3.Size = new System.Drawing.Size (112, 16);
    118.       label3.Font = new System.Drawing.Font ("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Bold);
    119.       label3.TabIndex = 9;
    120.       btnOrder.Location = new System.Drawing.Point (8, 440);
    121.       btnOrder.Size = new System.Drawing.Size (120, 32);
    122.       btnOrder.TabIndex = 6;
    123.       btnOrder.Text = "Confirm Order";
    124.       btnOrder.Click += new System.EventHandler (this.btnOrder_Click);
    125.       label1.Location = new System.Drawing.Point (16, 56);
    126.       label1.Text = "Sales Person";
    127.       label1.Size = new System.Drawing.Size (144, 24);
    128.       label1.TabIndex = 7;
    129.       label2.Location = new System.Drawing.Point (176, 8);
    130.       label2.Text = "Radio Options:";
    131.       label2.Size = new System.Drawing.Size (144, 16);
    132.       label2.Font = new System.Drawing.Font ("Microsoft Sans Serif", 9, System.Drawing.FontStyle.Bold);
    133.       label2.TabIndex = 8;
    134.       this.Text = "Car Configurator";
    135.       this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
    136.       this.ClientSize = new System.Drawing.Size (456, 485);
    137.       groupBox1.Controls.Add (this.radioPink);
    138.       groupBox1.Controls.Add (this.radioYellow);
    139.       groupBox1.Controls.Add (this.radioRed);
    140.       groupBox1.Controls.Add (this.radioGreen);
    141.       this.Controls.Add (this.label5);
    142.       this.Controls.Add (this.monthCalendar);
    143.       this.Controls.Add (this.label3);
    144.       this.Controls.Add (this.label2);
    145.       this.Controls.Add (this.label1);
    146.       this.Controls.Add (this.comboSalesPerson);
    147.       this.Controls.Add (this.carMakeList);
    148.       this.Controls.Add (this.checkedBoxRadioOptions);
    149.       this.Controls.Add (this.btnOrder);
    150.       this.Controls.Add (this.checkFloorMats);
    151.       this.Controls.Add (this.groupBox1);
    152.     }
    153.     static void Main()
    154.     {
    155.       Application.Run(new CarConfigForm());
    156.     }
    157.  
    158.     protected void btnOrder_Click (object sender, System.EventArgs e)
    159.     {
    160.       if(comboSalesPerson.Text != "")
    161.         Console.WriteLine("Sales Person: " + comboSalesPerson.Text);
    162.       else
    163.         Console.WriteLine("You did not select a sales person!");
    164.  
    165.       if(carMakeList.SelectedItem != null)
    166.         Console.WriteLine("Make: " + carMakeList.SelectedItem);
    167.  
    168.       if(checkFloorMats.Checked)
    169.         Console.WriteLine("You want floor mats.");  
    170.  
    171.       if(radioRed.Checked)
    172.         Console.WriteLine("You want a red exterior.");
    173.      
    174.       if(radioYellow.Checked)
    175.         Console.WriteLine("You want a yellow exterior.");
    176.      
    177.       if(radioGreen.Checked)
    178.         Console.WriteLine("You want a green exterior.");
    179.  
    180.       if(radioPink.Checked)
    181.         Console.WriteLine("Why do you want a PINK exterior?");
    182.      
    183.       for(int i = 0; i < checkedBoxRadioOptions.Items.Count; i++)
    184.       {
    185.         if(checkedBoxRadioOptions.GetItemChecked(i))
    186.         {
    187.           Console.WriteLine("Radio Item: "+ checkedBoxRadioOptions.Items[i]);
    188.         }                
    189.       }
    190.  
    191.       DateTime startD = monthCalendar.SelectionStart;
    192.       DateTime endD = monthCalendar.SelectionEnd;
    193.  
    194.       string dateStartStr = startD.Date.ToShortDateString();
    195.       string dateEndStr = endD.Date.ToShortDateString();
    196.      
    197.       if(dateStartStr != dateEndStr)
    198.       {
    199.         Console.WriteLine("Date between" + dateStartStr + " and" + dateEndStr);      
    200.       } else{
    201.         Console.WriteLine("You chose a single date:" + dateStartStr);
    202.             }
    203.     }
    204.  
    205.     protected void groupBox1_Leave (object sender, System.EventArgs e)
    206.     {
    207.       groupBox1.Text = "Exterior Color: Thanks for visiting the group...";
    208.     }
    209.  
    210.     protected void groupBox1_Enter (object sender, System.EventArgs e)
    211.     {
    212.       groupBox1.Text = "Exterior Color: You are in the group...";
    213.     }
    214.   }
    None!

  2. #2
    Ngày gia nhập
    11 2014
    Nơi ở
    Ho Chi Minh City, Vietnam, Vietnam
    Bài viết
    2

    Code này bạn tạo mới hoàn toàn 1 calendar bằng code à, có đụng đến calendar pick có sẵn trong C# không bạn?

Các đề tài tương tự

  1. Calendar trong ASP.NET MVC
    Gửi bởi tungkontin trong diễn đàn Nhập môn lập trình C#, ASP.NET
    Trả lời: 1
    Bài viết cuối: 14-11-2011, 08:43 PM
  2. Tạo Calendar trong winform với lập trình C#
    Gửi bởi thanhdat1004 trong diễn đàn Thắc mắc lập trình C#
    Trả lời: 5
    Bài viết cuối: 27-01-2011, 10:05 AM
  3. Customize calendar | Muốn calendar chỉ hiện thị một khoảng thời gian?
    Gửi bởi thanhthanh0910 trong diễn đàn Thắc mắc lập trình C#
    Trả lời: 1
    Bài viết cuối: 25-11-2010, 03:12 PM
  4. Định dạng cho Calendar ở webform trong lập trình C#?
    Gửi bởi leanhvi trong diễn đàn Thắc mắc lập trình C#
    Trả lời: 1
    Bài viết cuối: 28-10-2010, 05:06 PM
  5. Sử dụng Calendar Control trong lập trình C#
    Gửi bởi Xcross87 trong diễn đàn Tutorials và Thủ thuật lập trình C#, ASP.NET
    Trả lời: 0
    Bài viết cuối: 28-06-2007, 03:20 PM

Quyền hạn của bạn

  • Bạn không thể gửi đề tài mới
  • Bạn không thể gửi bài trả lời
  • Bạn không thể gửi các đính kèm
  • Bạn không thể chỉnh sửa bài viết của bạn