How to Customize a MonthCalendar in VB.NET


The Microsoft VB.NET MonthCalendar control allows users to select a date using a monthly calendar view. If you need to customize the look of the MonthCalendar control, you can change the title font, background and foreground colors of the calendar. You can also limit the date and times that you display with the MinDate and MaxDate properties of the control. By setting the "MonthCalendar.BoldedDates" property with the array of chosen values you can assign which dates will be displayed in bold.

  • Click "Start" in Windows and then click "Microsoft Visual Studio."

  • Click "File," select "Open" and then double-click on the VB.NET program in which you want to modify the MonthCalendar control.

  • Enter the following code after the "Public Class Main ()" line to change the color of the calendar and set the range of dates to display on the MonthCalendar control:

    Imports System

    Imports System.Windows.Forms

    Public NotInheritable Class Form1

    Inherits System.Windows.Forms.Form

    Public Shared Sub Main()

    System.Windows.Forms.Application.Run(New Form1)

    End Sub 'Main

    Public Sub New()


    ' Create the calendar.

        Me.MonthCalendar1 = New 


    ' Set the calendar location.

        Me.MonthCalendar1.Location = New System.Drawing.Point

    (47, 16)

    ' Change the color.

        Me.MonthCalendar1.BackColor = 


        Me.MonthCalendar1.ForeColor = 

    System.Drawing.Color.FromArgb( _

    ' Add dates to MonthlyBoldedDates array.

        Me.MonthCalendar1.MonthlyBoldedDates = New 

    System.DateTime() _ {New System.DateTime(2011, 9, 15, 0, 0, 0,

    0), _ New System.DateTime(2002, 9, 30, 0, 0, 0, 0)}

    ' Sets the maximum visible date on the calendar to 12/31/2011.

        Me.MonthCalendar1.MaxDate = New System.DateTime(2011, 

    12, 31, 0, 0, 0, 0)

    ' Set the minimum visible date on the calendar to 01/01/1999.

        Me.MonthCalendar1.MinDate = New System.DateTime(1999, 1, 

    1, 0, 0, 0, 0)

    End Sub

    ' Show the start and end dates in the text box.

        Me.TextBox1.Text = "Date Selected: Start = " + _ 

    e.Start.ToShortDateString() + " : End = " +


    End Sub

    End Class

  • Click "File" and then click "Save" to apply the change to the control in your VB.NET application.

Related Searches


  • Photo Credit Thomas Northcut/Photodisc/Getty Images
Promoted By Zergnet


You May Also Like

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!