我需要开发一个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
}
}
}
问题是,如何从ThisAddIn类中的Ribbon1类或任何其他地方调用公共方法?我知道我需要一个对象引用,但我怎么能找出实例的名称?我在现有文件中看不到ThisAddIn的任何实例被创建。或者我是否误解了概念,应该用其他方式完成?我将感谢任何关于创建Office插件的建议或信息链接。