次の方法で共有


方法: Windows フォーム MonthCalendar コントロールを使用して太字で特定の日を表示する

Windows フォーム MonthCalendar コントロールでは、単一の日付として、または繰り返し単位で、太字で日を表示できます。 これを行うと、休日や週末などの特別な日付に注意を引くことができます。

この機能は、3 つのプロパティによって制御されます。 BoldedDates プロパティには、1 つの日付が含まれています。 AnnuallyBoldedDates プロパティには、毎年太字で表示される日付が含まれています。 MonthlyBoldedDates プロパティには、毎月太字で表示される日付が含まれています。 これらの各プロパティには、DateTime オブジェクトの配列が含まれています。 これらのリストの 1 つから日付を追加または削除するには、DateTime オブジェクトを追加または削除する必要があります。

日付を太字で表示するには

  1. DateTime オブジェクトを作成します。

    Dim myVacation1 As Date = New DateTime(2001, 6, 10)  
    Dim myVacation2 As Date = New DateTime(2001, 6, 17)  
    
    DateTime myVacation1 = new DateTime(2001, 6, 10);  
    DateTime myVacation2 = new DateTime(2001, 6, 17);  
    
    DateTime myVacation1 = DateTime(2001, 6, 10);  
    DateTime myVacation2 = DateTime(2001, 6, 17);  
    
  2. MonthCalendar コントロールの AddBoldedDateAddAnnuallyBoldedDate、または AddMonthlyBoldedDate メソッドを呼び出して、1 つの日付を太字にします。

    MonthCalendar1.AddBoldedDate(myVacation1)  
    MonthCalendar1.AddBoldedDate(myVacation2)  
    
    monthCalendar1.AddBoldedDate(myVacation1);  
    monthCalendar1.AddBoldedDate(myVacation2);  
    
    monthCalendar1->AddBoldedDate(myVacation1);  
    monthCalendar1->AddBoldedDate(myVacation2);  
    

    –又は–

    DateTime オブジェクトの配列を作成し、いずれかのプロパティに割り当てることで、一連の日付を一度に太字にします。

    Dim VacationDates As DateTime() = {myVacation1, myVacation2}  
    MonthCalendar1.BoldedDates = VacationDates  
    
    DateTime[] VacationDates = {myVacation1, myVacation2};  
    monthCalendar1.BoldedDates = VacationDates;  
    
    Array<DateTime>^ VacationDates = {myVacation1, myVacation2};  
    monthCalendar1->BoldedDates = VacationDates;  
    

日付を通常のフォントで表示するには

  1. RemoveBoldedDateRemoveAnnuallyBoldedDate、または RemoveMonthlyBoldedDate メソッドを呼び出して、通常のフォントで 1 つの太字の日付を表示します。

    MonthCalendar1.RemoveBoldedDate(myVacation1)  
    MonthCalendar1.RemoveBoldedDate(myVacation2)  
    
    monthCalendar1.RemoveBoldedDate(myVacation1);  
    monthCalendar1.RemoveBoldedDate(myVacation2);  
    
    monthCalendar1->RemoveBoldedDate(myVacation1);  
    monthCalendar1->RemoveBoldedDate(myVacation2);  
    

    –又は–

    RemoveAllBoldedDatesRemoveAllAnnuallyBoldedDates、または RemoveAllMonthlyBoldedDates メソッドを呼び出して、3 つのリストのいずれかから太字の日付をすべて削除します。

    MonthCalendar1.RemoveAllBoldedDates()  
    
    monthCalendar1.RemoveAllBoldedDates();  
    
    monthCalendar1->RemoveAllBoldedDates();  
    
  2. UpdateBoldedDates メソッドを呼び出して、フォントの外観を更新します。

    MonthCalendar1.UpdateBoldedDates()  
    
    monthCalendar1.UpdateBoldedDates();  
    
    monthCalendar1->UpdateBoldedDates();  
    

関連項目