カレンダーの使い方

MonthCalendarをFormに貼り付けるだけで
月のカレンダーを簡単に表示することができます。

例では当日の日付が□で囲まれています(デフォルトで囲まれます)
さらに日付を選ぶと(マウスドラッグで範囲選択可能)
その開始日と終了日をラベルに表示しています。

monthcalendar

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

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 日付が選択された場合に発生するイベントを設定
            monthCalendar1.DateSelected += new DateRangeEventHandler(monthCalendar1_DateSelected);
        }

        void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {
            // 開始~終了を表示
            label1.Text = e.Start.ToString() + " ~ " + e.End.ToString();
        }
    }
}

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)