MonthCalendar.BoldedDates : MonthCalendar « System.Windows.Forms « C# / C Sharp by API






MonthCalendar.BoldedDates

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
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());
    }
}

   
  








Related examples in the same category

1.new MonthCalendar()
2.MonthCalendar.CalendarDimensions
3.MonthCalendar.DateChanged
4.MonthCalendar.DateSelected
5.MonthCalendar.FirstDayOfWeek
6.MonthCalendar.MaxSelectionCount