Csharp/C Sharp by API/System.Windows.Forms/MonthCalendar — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 12:09, 26 мая 2010
Содержание
MonthCalendar.BoldedDates
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void addButton_Click(object sender, EventArgs e)
{
System.DateTime[] boldDates = new System.DateTime[monthCalendar.BoldedDates.Length + 1];
int i =0;
foreach (DateTime currentDate in monthCalendar.BoldedDates)
{
boldDates[i] = currentDate;
i++;
}
boldDates[i] = System.DateTime.Parse(specialDate.Text);
monthCalendar.BoldedDates = boldDates;
}
private void monthCalendar_DateSelected(object sender, DateRangeEventArgs e)
{
specialDate.Text = e.Start.ToLongDateString();
}
}
partial class Form1
{
private void InitializeComponent()
{
System.Windows.Forms.Label label1;
System.Windows.Forms.Button addButton;
this.monthCalendar = new System.Windows.Forms.MonthCalendar();
this.specialDate = new System.Windows.Forms.DateTimePicker();
label1 = new System.Windows.Forms.Label();
addButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.Location = new System.Drawing.Point(12, 16);
label1.Name = "label1";
label1.Size = new System.Drawing.Size(90, 13);
label1.TabIndex = 2;
label1.Text = "Pick a date to add";
//
// addButton
//
addButton.Location = new System.Drawing.Point(289, 9);
addButton.Name = "addButton";
addButton.Size = new System.Drawing.Size(75, 23);
addButton.TabIndex = 3;
addButton.Text = "Add";
addButton.Click += new System.EventHandler(this.addButton_Click);
//
// monthCalendar
//
this.monthCalendar.CalendarDimensions = new System.Drawing.Size(3, 3);
this.monthCalendar.Location = new System.Drawing.Point(18, 74);
this.monthCalendar.Name = "monthCalendar";
this.monthCalendar.Size = new System.Drawing.Size(542, 439);
this.monthCalendar.TabIndex = 0;
this.monthCalendar.DateSelected += new System.Windows.Forms.DateRangeEventHandler(this.monthCalendar_DateSelected);
//
// specialDate
//
this.specialDate.Location = new System.Drawing.Point(108, 12);
this.specialDate.Name = "specialDate";
this.specialDate.Size = new System.Drawing.Size(175, 20);
this.specialDate.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(573, 529);
this.Controls.Add(addButton);
this.Controls.Add(label1);
this.Controls.Add(this.specialDate);
this.Controls.Add(this.monthCalendar);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.MonthCalendar monthCalendar;
private System.Windows.Forms.DateTimePicker specialDate;
}
public class DataTimePickerBoldedDates
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
MonthCalendar.CalendarDimensions
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();
}
}
MonthCalendar.DateChanged
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();
}
}
MonthCalendar.DateSelected
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();
}
}
MonthCalendar.FirstDayOfWeek
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();
}
}
MonthCalendar.MaxSelectionCount
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();
}
}
new MonthCalendar()
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Calendar : System.Windows.Forms.Form
{
private System.Windows.Forms.MonthCalendar monthCalendar1;
private System.Windows.Forms.Button button1;
private System.ruponentModel.Container components = null;
public Calendar()
{
InitializeComponent();
}
private void InitializeComponent()
{
this.monthCalendar1 = new System.Windows.Forms.MonthCalendar();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// monthCalendar1
//
this.monthCalendar1.FirstDayOfWeek = System.Windows.Forms.Day.Thursday;
this.monthCalendar1.Location = new System.Drawing.Point(16, 16);
this.monthCalendar1.Name = "monthCalendar1";
this.monthCalendar1.ShowTodayCircle = false;
this.monthCalendar1.ShowWeekNumbers = true;
this.monthCalendar1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(48, 184);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Selection Range";
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// Calendar
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 213);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button1,
this.monthCalendar1});
this.Name = "Calendar";
this.Text = "Calendar Control";
this.Load += new System.EventHandler(this.Calendar_Load);
this.ResumeLayout(false);
}
[STAThread]
static void Main()
{
Application.Run(new Calendar());
}
private void Calendar_Load(object sender, System.EventArgs e)
{
string str = monthCalendar1.Text.ToString() ;
}
private void button1_Click(object sender, System.EventArgs e)
{
}
private void button1_Click_1(object sender, System.EventArgs e)
{
// Get the selection Range.
SelectionRange sr = monthCalendar1.SelectionRange;
// Get the start of Range.
DateTime st = sr.Start;
// Get the end of Range.
DateTime se = sr.End ;
MessageBox.Show("RANGE START = " + st.ToString() + "\nRANGE END = " + se.ToString(), "Range Selection");
}
}