3

我是程序员菜鸟,我必须创建outlook 2007 插件。我应该在功能区或任务栏上创建一个按钮,但在收件箱中的单个邮件的窗口上创建一个按钮。您知道,当您双击收件箱中的邮件时,会出现新窗口。在那个窗口中,我需要一个按钮来打开一个带有一些树视图的新表单。对我来说主要问题是如何创建该按钮。这对我来说是全新的,所以我会非常感谢你的帮助。

4

2 回答 2

4

好的,我已经做了一些研究,下面的代码有点工作:) 但如果有经验的人能看到这个并告诉我它是否可以以及我可以改变什么以及如何改变它,我将非常感激。这只是更大项目的开始。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Windows.Forms;

namespace OutlookAddInMishko
{
    public partial class ThisAddIn
    {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            Inspectors = this.Application.Inspectors;
            Inspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code


        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

        #endregion


          private Office.CommandBarButton buttonOne;

        private Outlook.Inspectors Inspectors;
        public static Microsoft.Office.Interop.Outlook.Inspector InsMail;

        void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
        {
            Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;

            if (Inspector.CurrentItem is Outlook.MailItem)
            {
                tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
                bool exists = false;
                foreach (Office.CommandBar cmd in Inspector.CommandBars)
                {
                    if (cmd.Name == "EAD")
                    {
                        //exists = true;
                        cmd.Delete();
                    }
                }

                Office.CommandBar newMenuBar = Inspector.CommandBars.Add("EAD", Office.MsoBarPosition.msoBarTop, false, true);
                buttonOne = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);

                if (!exists)
                {
                    buttonOne.Caption = "Scan this mail";
                    buttonOne.Style = Office.MsoButtonStyle.msoButtonCaption;
                    buttonOne.FaceId = 1983;

                    //Register send event handler
                    buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);
                    newMenuBar.Visible = true;
                }
            }


        }


        private void buttonOne_Click(Office.CommandBarButton ctrl, ref bool cancel)
        {
            ProcessMessages();
        }

        private Form1 form1 = null;

        private void ProcessMessages()
        {
            if (form1 == null)
            {
                form1 = new Form1(this.Application);
            }
            form1.ShowDialog();
        }


    }
}


namespace OutlookAddInMishko
{
    public partial class Form1 : Form
    {
        protected Outlook.Application App;
        public Form1()
        {
            InitializeComponent();
        }
        public Form1(Outlook.Application _app)
        {
            App = _app;
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            label1.Text = "Total number of mails in inbox: " + App.ActiveExplorer().CurrentFolder.Items.Count.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Outlook.MailItem item = (Outlook.MailItem)App.ActiveInspector().CurrentItem;
            textBox1.Text += "From:    " + item.SenderName + "\r\n\n";
            textBox1.Text += "Subject: " + item.Subject + "\r\n\n";
            textBox1.Text += "Body: \r\n\n" + item.Body + "\r\n";
            textBox1.Text += "Mail contains:    " + item.Attachments.Count + " attachment(s).\r\n\n";
        }
    }
}
于 2009-12-23T17:26:43.940 回答
0

如果您打开在表单顶部显示邮件消息的窗口,您应该在功能区上有几个按钮(保存、撤消、重做等)。一直到右边是一个向下的三角形,上面有一条线,工具提示说:自定义快速访问工具栏。单击它,然后选择“更多命令”。在该屏幕中选择“自定义”选项卡。我认为您可以在此处添加一个按钮来显示您的表单。我没有任何自定义表格,所以我无法验证,希望这有效。

于 2009-12-22T16:17:20.030 回答