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 方法标记和显示从文件中读取的粗体字体日期。 本示例要求已将名为 monthCalendar1 的控件添加到一个MonthCalendarForm控件中,并且此方法放置在窗体中并从中调用。

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

适用于

另请参阅