Monday, November 23, 2009

Adding mouse over events to a .NET Calendar Control

The .NET calendar control is handy way to display a functional calendar. However, the styling of the control out of the box is pretty generic.

One way to spruce things up is to enable a mouse over as the user is browsing the dates.

Below is the code I used to do this. This code should be placed in the DayRender sub of the calendar control:

'Create colors for the mouse over and out

Dim onmouseoverStyle As String = "this.style.backgroundColor='#A8C0D0';"
Dim onmouseoutStyle As String = "this.style.backgroundColor='@BackColor'"

'create a variable to hold the row back color
Dim rowBackColor As String = String.Empty

'Add the attributes to the individual calendar day cells
e.Cell.Attributes.Add("onmouseover", onmouseoverStyle)
e.Cell.Attributes.Add("onmouseout", onmouseoutStyle.Replace("@BackColor", rowBackColor))

No comments: