【问题标题】:VSTO outlook scan opened itemVSTO Outlook 扫描打开的项目
【发布时间】:2012-04-03 23:23:58
【问题描述】:

我的解决方案有点奇怪。 我想扫描特定的字符串(这些特定的字符串已经在 XML 数据文件中)来实现这一点,我已经考虑通过以下步骤来实现这一点 我将有一个菜单项来更改加载项的设置(现在不需要) 我会在这样的栏中有一个像新按钮这样的按钮

http://www.packtpub.com/article/microsoft-office-outlook-programming-vsto-c-sharp-part1

然后说用户正在阅读在阅读窗格中选择并打开的项目。当我按下按钮时,我希望代码扫描主题和正文以与我的 xml 数据匹配,如果存在则显示一个消息框。

我已经创建了一个菜单项和菜单栏按钮以及 xml 数据,现在我的问题是如何扫描当前正在读取的项目?

这是我在 thisaddin.cs 中的 C# 代码

  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 Sql_openertake1
{
    public partial class ThisAddIn
    {
        private Office.CommandBar menuBar;
        private Office.CommandBarPopup newMenuBar;
        private Office.CommandBarButton buttonOne;
        Office.CommandBarButton PacktButtonA;
        Office.CommandBar PacktCustomToolBar;

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

         // Verify the PacktCustomToolBar exist and add to the application
if (PacktCustomToolBar == null)
{
// Adding the commandbar to Active explorer
Office.CommandBars PacktBars = this.Application.
ActiveExplorer().CommandBars;
// Adding PacktCustomToolBar to the commandbars
PacktCustomToolBar = PacktBars.Add("SQL Opener",Office.MsoBarPosition.msoBarTop, false, true);
}
// Adding button to the custom tool bar
Office.CommandBarButton MyButton1 = (Office.
CommandBarButton)PacktCustomToolBar.Controls.Add(1,
missing, missing, missing, missing);
// Set the button style
MyButton1.Style = Office.MsoButtonStyle.msoButtonCaption;
// Set the caption and tag string
MyButton1.Caption = "Open";
MyButton1.Tag = "MY BUTTON";
if (this.PacktButtonA == null)
{
// Adding the event handler for the button in the toolbar
this.PacktButtonA = MyButton1;
PacktButtonA.Click += new Office.
_CommandBarButtonEvents_ClickEventHandler(ButtonClick);
}
}
// Button event in the custom toolbar
private void ButtonClick(Office.CommandBarButton ButtonContrl,
ref bool CancelOption)
{
// Message box displayed on button click
MessageBox.Show(ButtonContrl.Caption + " Says Hello World!");
}

        private void AddMenuBar()
        {
            try
            {
                menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
                    Office.MsoControlType.msoControlPopup, missing,
                    missing, missing, true);
                if (newMenuBar != null)
                {
                    newMenuBar.Caption = "SQL Opener";
                    buttonOne = (Office.CommandBarButton)newMenuBar.Controls.
                    Add(Office.MsoControlType.msoControlButton, missing,
                        missing, 1, true);
                    buttonOne.Style = Office.MsoButtonStyle.
                        msoButtonIconAndCaption;
                    buttonOne.Caption = "Settings";
                    buttonOne.FaceId = 0548;
                    buttonOne.Tag = "c123";
                    buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);
                    newMenuBar.Visible = true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }

        private void buttonOne_Click(Office.CommandBarButton ctrl,
            ref bool cancel)
        {
            System.Windows.Forms.MessageBox.Show("You clicked: " + ctrl.Caption,
                "Custom Menu", System.Windows.Forms.MessageBoxButtons.OK);

        }


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

        private void createnewform()
        {
            SAmple_form sform = new SAmple_form();
            sform.Text = "Show the Count";


        }

        #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
    }
}

这是我的 xml 数据

<?xml version="1.0" encoding="utf-8" ?>
<words>
    <word id="5001">None</word>
    <word id="5002">Glazed</word>
    <word id="5005">Sugar</word>
    <word id="5006">Sprinkles</word>
    <word id="5003">Chocolate</word>
    <word id="5004">Maple</word>

</words>

感谢您的帮助。

【问题讨论】:

    标签: c# outlook vsto outlook-addin


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2016-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2014-04-26
    • 2012-04-15
    • 1970-01-01
    相关资源
    最近更新 更多