■ RibbonButton 인터페이스를 사용해 커스텀 버튼을 추가하는 방법을 보여준다.
▶ CustomRibbon.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using Microsoft.Office.Tools.Ribbon; using System; using System.Windows.Forms; namespace TestProject { /// <summary> /// 커스텀 리본 /// </summary> public partial class CustomRibbon { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 리본 베이스 로드시 처리하기 - RibbonBase_Load(sender, e) /// <summary> /// 리본 베이스 로드시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void RibbonBase_Load(object sender, RibbonUIEventArgs e) { this.customButtom.Click += customButtom_Click; } #endregion #region 커스텀 버튼 클릭시 처리하기 - customButtom_Click(sender, e) /// <summary> /// 커스텀 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void customButtom_Click(object sender, RibbonControlEventArgs e) { MessageBox.Show(DateTime.Now.ToString()); } #endregion } } |
▶ CustomAddIn.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; namespace TestProject { /// <summary> /// 커스텀 애드인 /// </summary> public partial class CustomAddIn { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 커스텀 애드인 시작시 처리하기 - CustomAddIn_Startup(sender, e) /// <summary> /// 커스텀 애드인 시작시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void CustomAddIn_Startup(object sender, EventArgs e) { } #endregion #region 커스텀 애드인 셧다운시 처리하기 - CustomAddIn_Shutdown(sender, e) /// <summary> /// 커스텀 애드인 셧다운시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void CustomAddIn_Shutdown(object sender, EventArgs e) { } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region VSTO에서 생성한 코드 /// <summary> /// 디자이너 지원에 필요한 메서드입니다. /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(CustomAddIn_Startup ); this.Shutdown += new System.EventHandler(CustomAddIn_Shutdown); } #endregion } } |