共用方式為


建立全天活動的約會

此範例示範如何使用 AllDayEvent 屬性來建立全天活動的約會。

範例

注意事項

下列程式代碼範例是 Microsoft Office Outlook 2007 程式設計應用程式的摘錄。

事件與一般約會不同,因為它是持續 24 小時或更久的活動。 事件的範例包括交易示範、假期或假期。 事件和年度事件不會在使用者的行事曆中顯示為佔用的時間區塊。 相反地,它們會顯示為橫幅。 您可以在行事曆日或周檢視的頂端看到橫幅。 對於全天約會,根據預設,用戶的時間在其他人檢視時會顯示為忙碌,但用戶的時間會顯示為免費的活動或年度活動。

若要以程序設計方式建立全天事件,請將 AppointmentItem 物件的 AllDayEvent 屬性設定為 true。 然後設定 AppointmentItem 的 StartEnd 屬性。 如果您將 AllDayEvent 屬性設定為 true,但未設定 Start 和 End 屬性,則事件會在今天發生,而且會是約會,顯示行事曆上的忙碌狀態。 如果您想要在未來的日期發生事件,則必須設定 Start 和 End 屬性。

注意事項

若要將約會設為全天活動,您必須將 Start 屬性設定為上午 12:00。 (在您想要開始活動當天午夜) ,並將 End 屬性設定為 12:00 A.M. 如果您將 [開始] 或 [結束時間] 設定為上午 12:00 以外的日期和時間值,則約會會變成多日約會,而不是全天活動。

例如,如果您的事件持續時間只有一天,請將 Start 屬性設定為您希望事件開始的當天上午 12:00,並將 End 屬性設定為 12:00 A.M. 在下一天。 在開始日期之後的一天以上,您應該一律將 End 屬性設定為上午 12:00。

在下列程式代碼範例中,AllDayEventExample 會建立從 2007 年 6 月 11 日開始,到 2007 年 6 月 15 日結束的全天事件。 請注意,約會的 End 屬性設定為 2007 年 6 月 16 日上午 12:00。

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void AllDayEventExample()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.Subject = "Developer's Conference";
    appt.AllDayEvent = true;
    appt.Start = DateTime.Parse("6/11/2007 12:00 AM");
    appt.End = DateTime.Parse("6/16/2007 12:00 AM");
    appt.Display(false);
}

另請參閱