共用方式為


使用 [選取名稱] 對話框來取得並指派約會的收件者

此範例示範如何使用 [ 選取名稱 ] 對話框來取得並指派收件者給約會專案。

範例

注意事項

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

若要顯示 [選取名稱] 對話框,請呼叫 SelectNamesDialog 物件的 Display () 方法。 向使用者顯示 [ 選取名稱 ] 對話框之後,程式代碼執行就會停止,直到使用者按兩下 [ 確定 ] 或關閉對話框為止。 若要將初始收件者設定為顯示在對話框中,或是要在對話框中選取收件者,請使用 SelectNamesDialog 物件的 Recipients 屬性。 這會傳回與 SelectNamesDialog 相關聯的 Recipients 集合。 若要將 Recipient 物件新增至 SelectNamesDialog的 Recipients 集合,請使用集合的 Add 方法,並指定 Recipient 物件的 Type 屬性。

在下列程式代碼範例中,DemoSelectNamesDialogRecipients 會建立 AppointmentItem 物件,並設定其部分屬性。 然後,它會建立 SelectNamesDialog ,並使用 SetDefaultDisplayMode (OlDefaultSelectNamesDisplayMode) 方法來設定 [ 選取名稱 ] 對話框的會議顯示模式。 此範例會在 資源 收件者選取器中填入字串 「Conf Room 36/2739」。。 向使用者顯示對話框之後,程式代碼會列舉與這個 SelectNamesDialog 實例相關聯的 Recipients 集合,並將這些收件者新增至所建立的約會。 最後,此範例會向用戶顯示會議邀請。

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 DemoSelectNamesDialogRecipients()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;
    appt.Subject = "Team Morale Event";
    appt.Start = DateTime.Parse("5/17/2007 11:00 AM");
    appt.End = DateTime.Parse("5/17/2007 12:00 PM");
    Outlook.SelectNamesDialog snd =
        Application.Session.GetSelectNamesDialog();
    snd.SetDefaultDisplayMode(
        Outlook.OlDefaultSelectNamesDisplayMode.olDefaultMeeting);
    Outlook.Recipient confRoom =
        snd.Recipients.Add("Conf Room 36/2739");
    // Explicitly specify Recipient.Type.
    confRoom.Type = (int)Outlook.OlMeetingRecipientType.olResource;
    snd.Recipients.ResolveAll();
    snd.Display();
    // Add Recipients to meeting request.
    Outlook.Recipients recips = snd.Recipients;
    if (recips.Count > 0)
    {
        foreach (Outlook.Recipient recip in recips)
        {
            appt.Recipients.Add(recip.Name);
        }
    }
    appt.Recipients.ResolveAll();
    appt.Display(false);
}

另請參閱