【发布时间】:2011-11-27 10:56:25
【问题描述】:
我需要开发一个 Outlook 2010 插件,而且我是 Visual Studio 和 C# 的新手,因为我主要使用 PHP 和 JavaScript。我正在使用 Visual Studio 2010,并使用内置 Outlook 2010 加载项模板创建了一个项目。考虑以下代码:
// file ThisAddIn.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
namespace OutlookAddIn1
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
public string displayCount()
{
Outlook.MAPIFolder inbox = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true");
return string.Format("Unread items in Inbox = {0}", unreadItems.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
}
}
// file Ribbon1.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn1
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
// call ThisAddIn.displayCount() here
}
}
}
问题是,如何从 Ribbon1 类或其他任何地方的 ThisAddIn 类调用公共方法?我知道我需要一个对象引用,但是我怎样才能找到一个实例的名称呢?我看不到在现有文件的任何地方创建了 ThisAddIn 的实例。还是我误解了这个概念,应该以其他方式完成?我也将不胜感激有关创建 Office 加载项的任何建议或信息链接。
【问题讨论】:
标签: c# visual-studio visual-studio-2010 outlook outlook-addin