MonthCalendar.AddBoldedDate(DateTime) Metoda

Definicja

Dodaje dzień, który ma być wyświetlany pogrubioną w kalendarzu miesiąca.

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

Parametry

date
DateTime

Data, która ma być wyświetlana pogrubioną.

Przykłady

Poniższy przykład kodu używa AddBoldedDate metod i UpdateBoldedDates do oznaczania i wyświetlania w pogrubionych datach czcionek odczytanych z pliku. Ten przykład wymaga dodania MonthCalendar kontrolki o nazwie monthCalendar1, do Form obiektu i że ta metoda jest umieszczana w formularzu i wywoływana z niego.

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

Uwagi

Następnie należy wywołać metodę, UpdateBoldedDates aby zaktualizować ekran.

Aby dodać wiele dat w jednym przypisaniu, można przypisać tablicę DateTime obiektów do BoldedDates właściwości.

Dotyczy

Zobacz też