Outlook 2010 추가 기능을 개발해야하며 대부분 PHP와 JavaScript를 사용하므로 Visual Studio와 C#을 처음 사용합니다. Visual Studio 2010을 사용하고 있으며 기본 제공 Outlook 2010 추가 기능 템플릿을 사용하여 프로젝트를 만들었습니다. folowing 코드를 살펴 보자 :Outlook 2010 addin C# 공개 메서드
// 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 클래스의 public 메소드를 호출하거나 할 수있다? 나는 객체 참조가 필요하다는 것을 알고 있지만 인스턴스의 이름을 어떻게 알 수 있습니까? ThisAddIn 인스턴스가 기존 파일의 어느 곳에서나 생성되는 것을 볼 수 없습니다. 아니면 개념을 오해하고 다른 방법으로 수행해야합니까? Office 어드벤스를 만드는 방법에 대한 조언이나 링크를 보내 주시면 감사하겠습니다.
코드 샘플을 제공해 주시겠습니까? – noname