2011-02-19 182 views

回答

8

這是不可能的。沒有內置的方式來定製單個日期或日期顯示在MonthCalendar控件上的方式。

可能所有者繪製控件,但這是太多的工作來證明。這會讓你負責自己繪製整個控制。請注意,如果您選擇走此路線,MonthCalendar控件不會引發Paint事件,因爲基本控件將UserPaint位設置爲「False」。您將不得不繼承控件的子類並覆蓋其OnPrint method

我不能親自推薦提供這種級別的自定義任何第三方控件,但快速谷歌搜索確實出現調高几個選項:

0

在Visual Studio 2005中,u從工具箱拖動MONTHCALENDAR。

轉到屬性。

每年都會顯示粗體日期,每月加粗日期和粗體日期。你可以在這些屬性中添加你想要的日期。

+0

VS 2010,Winform – 2011-02-19 05:02:58

+0

這隻會使日期加粗,我想改變一些特定日期的顏色 – 2011-02-19 05:04:09

-3

第1步:拖動網格視圖控制和日曆在Web窗體或窗體上:

步驟2:粘貼的.cs頁面上的編碼

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(); 
     } 

    } 
0

嘗試這種情況:

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 

此子塗料一個的MonthCalendar(MC)在一個特定的日期(數據)用一種顏色( cor)

相關問題