8

VB.NETのMonthCalendarコントロールで特定の日付の色を変更するにはどうすればよいですか?

たとえば、1月21日の色を赤に、日曜日をオレンジに変更する必要があります...

4

4 に答える 4

9

これは不可能です。コントロールに個々の曜日または日付を表示する方法をカスタマイズする組み込みの方法はありませんMonthCalendar

コントロールを所有者が描くこともできますが、それは正当化するにはあまりにも多くの作業です。これにより、コントロール全体を自分で描画する責任があります。このルートを選択した場合、ベースコントロールがビットを「False」に設定するため、コントロールはイベントを発生さMonthCalendarせないことに注意してください。コントロールをサブクラス化し、代わりにそのメソッドをオーバーライドする必要があります。PaintUserPaintOnPrint

このレベルのカスタマイズを提供するサードパーティのコントロールを個人的に推奨することはできませんが、Googleですばやく検索すると、いくつかのオプションが表示されます。

于 2011-02-19T06:48:29.017 に答える
0

Visual Studio 2005では、ツールボックスから月間カレンダーをドラッグします。

プロパティに移動します。

毎年太字の日付、月ごとの太字の日付、太字の日付があります。これらのプロパティに必要な日付を追加できます。

于 2011-02-19T04:46:05.363 に答える
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

このサブは、1つのMonthCalendar(mc)を1つの特定の日付(データ)に1つの色(cor)でペイントします

于 2016-06-02T10:46:29.790 に答える
-4

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

    }
于 2011-02-19T09:43:21.450 に答える