Bagikan melalui


Cara: Menampilkan Hari Tertentu dalam Tebal dengan Kontrol Formulir Windows MonthCalendar

Kontrol Formulir Windows MonthCalendar dapat menampilkan hari dalam jenis tebal, baik sebagai tanggal tunggal atau secara berulang. Anda mungkin melakukan ini untuk menarik perhatian pada tanggal khusus, seperti hari libur dan akhir pekan.

Tiga properti mengontrol fitur ini. Properti BoldedDates berisi tanggal tunggal. Properti AnnuallyBoldedDates berisi tanggal yang muncul dalam huruf tebal setiap tahun. Properti MonthlyBoldedDates berisi tanggal yang muncul dalam huruf tebal setiap bulan. Masing-masing properti ini berisi array DateTime objek. Untuk menambahkan atau menghapus tanggal dari salah satu daftar ini, Anda harus menambahkan atau menghapus DateTime objek.

Untuk membuat tanggal muncul dalam tipe tebal

  1. DateTime Buat objek.

    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. Buat satu tanggal tebal dengan memanggil AddBoldedDatemetode kontrol , AddAnnuallyBoldedDate, atau AddMonthlyBoldedDateMonthCalendar .

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

    –Atau–

    Buat sekumpulan tanggal ditebalkan sekaligus dengan membuat array DateTime objek dan menetapkannya ke salah satu properti.

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

Untuk membuat tanggal muncul dalam font reguler

  1. Buat satu tanggal tebal muncul dalam font reguler dengan memanggil RemoveBoldedDatemetode , , RemoveAnnuallyBoldedDateatau RemoveMonthlyBoldedDate .

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

    –Atau–

    Hapus semua tanggal tebal dari salah satu dari tiga daftar dengan memanggil RemoveAllBoldedDatesmetode , , RemoveAllAnnuallyBoldedDatesatau RemoveAllMonthlyBoldedDates .

    MonthCalendar1.RemoveAllBoldedDates()  
    
    monthCalendar1.RemoveAllBoldedDates();  
    
    monthCalendar1->RemoveAllBoldedDates();  
    
  2. Perbarui tampilan font dengan memanggil UpdateBoldedDates metode .

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

Baca juga