다음을 통해 공유


방법: Outlook에서 전자 메일 메시지를 보여 주는 사용자 지정 작업 창 표시

다음 코드 예제에서는 Outlook에서 열려 있는 모든 전자 메일 메시지의 검사기 창에 고유 사용자 지정 작업 창을 표시합니다. 이 항목의 코드 예제에 대한 사용 지침을 비롯한 자세한 내용은 연습: Outlook에서 전자 메일 메시지와 함께 사용자 지정 작업 창 표시를 참조하십시오.

적용 대상: 이 항목의 정보는 Outlook 2007 및 Outlook 2010의 응용 프로그램 수준 프로젝트에 적용됩니다. 자세한 내용은 Office 응용 프로그램 및 프로젝트 형식에 따라 사용 가능한 기능을 참조하십시오.

예제

ThisAddIn 코드 파일

  • 추가 기능에 있는 ThisAddIn.cs 또는 ThisAddIn.vb 파일의 내용을 다음 코드로 바꿉니다.

    Imports System.Collections.Generic
    Imports Microsoft.Office.Tools
    Imports Office = Microsoft.Office.Core
    Imports Outlook = Microsoft.Office.Interop.Outlook
    
    Public Class InspectorWrapper
        Private inspector As Outlook.Inspector
        Private WithEvents inspectorEvents As Outlook.InspectorEvents_Event
        Private WithEvents taskPane As CustomTaskPane
    
        Public Sub New(ByVal Inspector As Outlook.Inspector)
            Me.inspector = Inspector
            inspectorEvents = TryCast(Me.inspector, Outlook.InspectorEvents_Event)
            taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(New TaskPaneControl(), _
                "My task pane", Inspector)
        End Sub
    
        Private Sub TaskPane_VisibleChanged(ByVal sender As Object, ByVal e As EventArgs) _
            Handles taskPane.VisibleChanged
            Globals.Ribbons(inspector).ManageTaskPaneRibbon.ToggleButton1.Checked = taskPane.Visible
        End Sub
    
        Sub InspectorWrapper_Close() Handles inspectorEvents.Close
            If Not (taskPane Is Nothing) Then
                Globals.ThisAddIn.CustomTaskPanes.Remove(taskPane)
            End If
    
            taskPane = Nothing
            Globals.ThisAddIn.InspectorWrappers.Remove(inspector)
            RemoveHandler inspectorEvents.Close, AddressOf InspectorWrapper_Close
            inspector = Nothing
        End Sub
    
        Public ReadOnly Property CustomTaskPane() As CustomTaskPane
            Get
                Return taskPane
            End Get
        End Property
    End Class
    
    Public Class ThisAddIn
    
        Private inspectorWrappersValue As New Dictionary(Of Outlook.Inspector, InspectorWrapper)
        Private WithEvents inspectors As Outlook.Inspectors
    
        Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles Me.Startup
    
            inspectors = Me.Application.Inspectors
            Dim inspector As Outlook.Inspector
            For Each inspector In inspectors
                Inspectors_NewInspector(inspector)
            Next inspector
        End Sub
    
        Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) _
            Handles Me.Shutdown
    
            RemoveHandler inspectors.NewInspector, AddressOf Inspectors_NewInspector
            inspectors = Nothing
            inspectorWrappersValue = Nothing
        End Sub
    
        Sub Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector) _
            Handles inspectors.NewInspector
    
            If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
                inspectorWrappersValue.Add(Inspector, New InspectorWrapper(Inspector))
            End If
        End Sub
    
        Public ReadOnly Property InspectorWrappers() As Dictionary(Of Outlook.Inspector, InspectorWrapper)
            Get
                Return inspectorWrappersValue
            End Get
        End Property
    End Class
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    using Microsoft.Office.Tools;
    
    namespace OutlookMailItemTaskPane
    {
        public class InspectorWrapper
        {
            private Outlook.Inspector inspector;
            private CustomTaskPane taskPane;
    
            public InspectorWrapper(Outlook.Inspector Inspector)
            {
                inspector = Inspector;
                ((Outlook.InspectorEvents_Event)inspector).Close +=
                    new Outlook.InspectorEvents_CloseEventHandler(InspectorWrapper_Close);
    
                taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(
                    new TaskPaneControl(), "My task pane", inspector);
                taskPane.VisibleChanged += new EventHandler(TaskPane_VisibleChanged);
            }
    
            void TaskPane_VisibleChanged(object sender, EventArgs e)
            {
                Globals.Ribbons[inspector].ManageTaskPaneRibbon.toggleButton1.Checked = 
                    taskPane.Visible;
            }
    
            void InspectorWrapper_Close()
            {
                if (taskPane != null)
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(taskPane);
                }
    
                taskPane = null;
                Globals.ThisAddIn.InspectorWrappers.Remove(inspector);
                ((Outlook.InspectorEvents_Event)inspector).Close -=
                    new Outlook.InspectorEvents_CloseEventHandler(InspectorWrapper_Close);
                inspector = null;
            }
    
            public CustomTaskPane CustomTaskPane
            {
                get
                {
                    return taskPane;
                }
            }
        }
    
        public partial class ThisAddIn
        {
            private Dictionary<Outlook.Inspector, InspectorWrapper> inspectorWrappersValue =
                new Dictionary<Outlook.Inspector, InspectorWrapper>();
            private Outlook.Inspectors inspectors;
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                inspectors = this.Application.Inspectors;
                inspectors.NewInspector +=
                    new Outlook.InspectorsEvents_NewInspectorEventHandler(
                    Inspectors_NewInspector);
    
                foreach (Outlook.Inspector inspector in inspectors)
                {
                    Inspectors_NewInspector(inspector);
                }
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
                inspectors.NewInspector -=
                    new Outlook.InspectorsEvents_NewInspectorEventHandler(
                    Inspectors_NewInspector);
                inspectors = null;
                inspectorWrappersValue = null;
            }
    
            void Inspectors_NewInspector(Outlook.Inspector Inspector)
            {
                if (Inspector.CurrentItem is Outlook.MailItem)
                {
                    inspectorWrappersValue.Add(Inspector, new InspectorWrapper(Inspector));
                }
            }
    
            public Dictionary<Outlook.Inspector, InspectorWrapper> InspectorWrappers
            {
                get
                {
                    return inspectorWrappersValue;
                }
            }
    
            #region VSTO generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InternalStartup()
            {
                this.Startup += new System.EventHandler(ThisAddIn_Startup);
                this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
    
            #endregion
        }
    }
    

ManageTaskPaneRibbon 코드 파일

  • 추가 기능에 있는 ManageTaskPaneRibbon.cs 또는 ManageTaskPaneRibbon.vb 파일의 내용을 다음 코드로 바꿉니다.

    Imports Microsoft.Office.Tools.Ribbon
    Imports Outlook = Microsoft.Office.Interop.Outlook
    Imports Microsoft.Office.Tools
    
    Public Class ManageTaskPaneRibbon
    
        Private Sub ManageTaskPaneRibbon_Load(ByVal sender As System.Object, _
            ByVal e As Microsoft.Office.Tools.Ribbon.RibbonUIEventArgs) Handles MyBase.Load
    
        End Sub
    
        Private Sub ToggleButton1_Click(ByVal sender As System.Object, _
            ByVal e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) _
            Handles ToggleButton1.Click
    
            Dim inspector As Outlook.Inspector = e.Control.Context
            Dim inspectorWrapper As InspectorWrapper = Globals.ThisAddIn.InspectorWrappers(inspector)
            Dim taskPane As CustomTaskPane = inspectorWrapper.CustomTaskPane
            If Not (taskPane Is Nothing) Then
                taskPane.Visible = TryCast(sender, RibbonToggleButton).Checked
            End If
        End Sub
    End Class
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Microsoft.Office.Tools;
    
    namespace OutlookMailItemTaskPane
    {
        public partial class ManageTaskPaneRibbon : RibbonBase
        {
            public ManageTaskPaneRibbon()
                : base(Globals.Factory.GetRibbonFactory())
            {
                InitializeComponent();
            }
    
            private void ManageTaskPaneRibbon_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
            {
                Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;
                InspectorWrapper inspectorWrapper = Globals.ThisAddIn.InspectorWrappers[inspector];
                CustomTaskPane taskPane = inspectorWrapper.CustomTaskPane;
                if (taskPane != null)
                {
                    taskPane.Visible = ((RibbonToggleButton)sender).Checked;
                }
            }
        }
    }
    

참고 항목

작업

연습: Outlook에서 전자 메일 메시지와 함께 사용자 지정 작업 창 표시

방법: 응용 프로그램에 사용자 지정 작업 창 추가

연습: 사용자 지정 작업 창을 사용하여 응용 프로그램 자동화

연습: 사용자 지정 작업 창과 리본 단추 동기화

개념

여러 응용 프로그램 창의 사용자 지정 작업 창 관리

기타 리소스

사용자 지정 작업 창 개요

리본 개요

Outlook 개체 모델 개요