How to change the color of specific dates in a MonthCalendar control?

How to change the color of specific dates in a MonthCalendar control in VB.NET?

For example, I need to change the color on January 21 to red, on Sundays to orange, etc.

+6
winforms monthcalendar
source share
4 answers

It's impossible. There is no built-in way to customize how individual days or dates are displayed in the MonthCalendar control.

You can attract the owner, but too much work to justify. This will make you responsible for drawing all control yourself. Note that if you decide to go this route, the MonthCalendar control MonthCalendar not raise the Paint event, because the base control sets the UserPaint bit to False. You will have to subclass the control and override its OnPrint method .

I cannot personally recommend third-party controls that provide this level of customization, but a quick Google search seems to include several options:

+8
source share

In visual studio 2005, u drag monthcalendar from the toolbar.

Go to properties.

Dates, monthly bold dates, and bold dates are highlighted annually in bold. U can add u dates to these properties.

0
source share

Try the following:

 Private Sub pintaCalendarioNaData(ByRef mc As MonthCalendar, ByVal data As Date, ByVal cor As String) Dim gMonthCalendar As Graphics = mc.CreateGraphics() Dim oHTIMonths As MonthCalendar.HitTestInfo Dim arrDates As New ArrayList() Try For intRows As Integer = 1 To mc.Size.Width - 1 For intCols As Integer = 1 To mc.Size.Height - 1 oHTIMonths = mc.HitTest(intRows, intCols) If oHTIMonths.HitArea = MonthCalendar.HitArea.Date Then If CDate(mc.HitTest(intRows, intCols).Time) = CDate(data) Then gMonthCalendar.DrawRectangle(New Pen(ColorTranslator.FromHtml(cor), 2), intRows, intCols, 24, 15) GoTo fim End If End If Next intCols Next intRows fim: Catch ex As Exception MessageBox.Show("Error: " & vbNewLine & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Err.Clear() Finally End Try End Sub 

This sub-color highlights one MonthCalendar (mc) for one specific date (data) with one color (cor)

0
source share

Step 1: Drag the grid. Office and calendar in the form of a web form or window:

Step 2: insert the encoding on the .cs page

 using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Drawing; public partial class frmCalander : System.Web.UI.Page { SqlConnection con= new SqlConnection(); SqlDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; String strConn; protected void Page_Load(object sender, EventArgs e) { con.ConnectionString = ConfigurationManager.ConnectionStrings["STUDENTConnectionString"].ConnectionString; myda = new SqlDataAdapter("Select * from EventTable", con); myda.Fill(ds, "Table"); } protected void Calendar1_DayRender(object sender, DayRenderEventArgs e) { if (! e.Day.IsOtherMonth ) { foreach (DataRow dr in ds.Tables[0].Rows) { if ((dr["EventDate"].ToString() != DBNull.Value.ToString())) { DateTime dtEvent= (DateTime)dr["EventDate"]; if (dtEvent.Equals(e.Day.Date)) { e.Cell.BackColor = Color.PaleVioletRed; } } } } //If the month is not CurrentMonth then hide the Dates else { e.Cell.Text = ""; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { myda = new SqlDataAdapter("Select EventId, EventName, EventLocation, Convert(varchar,EventDate,105) as EventDate from EventTable where EventDate='" + Calendar1.SelectedDate.ToString() + "'", con); dsSelDate = new DataSet(); myda.Fill(dsSelDate, "AllTables"); if (dsSelDate.Tables[0].Rows.Count == 0) { GridView1.Visible = false; } else { GridView1.Visible = true; GridView1.DataSource = dsSelDate; GridView1.DataBind(); } } 
-3
source share

All Articles