MonthCalendar.AddBoldedDate(DateTime) 方法

定義

將粗體顯示的某天加入月曆中。

public:
 void AddBoldedDate(DateTime date);
public void AddBoldedDate (DateTime date);
member this.AddBoldedDate : DateTime -> unit
Public Sub AddBoldedDate (date As DateTime)

參數

date
DateTime

粗體顯示的日期。

範例

下列程式碼範例會使用 AddBoldedDateUpdateBoldedDates 方法來標記及顯示從檔案讀取的粗體字型日期。 這個範例要求 MonthCalendar 已將名為 monthCalendar1 的控制項新增至 , Form 而且這個方法會放在表單中,並從中呼叫。

private:
   // The following method uses Add to add dates that are 
   // bolded, followed by an UpdateBoldedDates to make the
   // added dates visible.
   void loadDates()
   {
      String^ myInput;
      try
      {
         StreamReader^ myInputStream = File::OpenText( "myDates.txt" );
         while ( (myInput = myInputStream->ReadLine()) != nullptr )
         {
            monthCalendar1->AddBoldedDate( DateTime::Parse( myInput->Substring( 0, myInput->IndexOf( " " ) ) ) );
            listBox1->Items->Add( myInput );
         }
         monthCalendar1->UpdateBoldedDates();
         myInputStream->Close();
         File::Delete( "myDates.txt" );
      }
      catch ( FileNotFoundException^ fnfe ) 
      {
         
         // Code to handle a file that could not be found should go here.
         Console::WriteLine( "An error occurred: '{0}'", fnfe );
      }

   }
// The following method uses Add to add dates that are 
// bolded, followed by an UpdateBoldedDates to make the
// added dates visible.

private void loadDates()
{
    String myInput ;
    try
    {
        StreamReader myInputStream = File.OpenText("myDates.txt");
        while((myInput = myInputStream.ReadLine()) != null)
        {
            monthCalendar1.AddBoldedDate(DateTime.Parse(myInput.Substring(0,myInput.IndexOf(" "))));
            listBox1.Items.Add(myInput);
        }
        monthCalendar1.UpdateBoldedDates();
        myInputStream.Close();
        File.Delete("myDates.txt");
    }catch(FileNotFoundException fnfe)
    {
        // Code to handle a file that could not be found should go here.
    Console.WriteLine("An error occurred: '{0}'", fnfe);
    }             
}
' The following method uses Add to add dates that are 
' bolded, followed by an UpdateBoldedDates to make the
' added dates visible.
Private Sub loadDates()
   Dim myInput As [String]
   Try
      Dim myInputStream As StreamReader = File.OpenText("myDates.txt")
      myInput = myInputStream.ReadLine()
      While myInput IsNot Nothing
         monthCalendar1.AddBoldedDate(DateTime.Parse(myInput.Substring(0, myInput.IndexOf(" "))))
         listBox1.Items.Add(myInput)
         myInput = myInputStream.ReadLine()
      End While
      monthCalendar1.UpdateBoldedDates()
      myInputStream.Close()
      File.Delete("myDates.txt")
   Catch fnfe As FileNotFoundException
   End Try
End Sub

備註

您之後必須呼叫 UpdateBoldedDates 方法來更新顯示器。

若要在單一指派中新增多個日期,您可以將物件的陣列 DateTime 指派給 BoldedDates 屬性。

適用於

另請參閱