12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using Word = Microsoft.Office.Interop.Word;
- using Office = Microsoft.Office.Core;
- using Microsoft.Office.Tools.Word;
- using Microsoft.Office.Core;
- namespace HTEXLabel
- {
- public partial class ThisAddIn
- {
- private Office.CommandBar customNavBar;
- private LableRibbon myRibbon;
- private void ThisAddIn_Startup(object sender, System.EventArgs e)
- {
- //AddCustomNavBar();
- LoadRibbon();
- }
- private void LoadRibbon()
- {
- // 在这里加载自定义 Ribbon
-
- }
- private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
- {
- }
- protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
- {
- return new LableRibbon();
- }
- #region VSTO 生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要修改
- /// 使用代码编辑器修改此方法的内容。
- /// </summary>
- private void InternalStartup()
- {
- this.Startup += new System.EventHandler(ThisAddIn_Startup);
- this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
- }
- #endregion
- private void AddCustomNavBar()
- {
- customNavBar = this.Application.CommandBars.Add("CustomNavBar", MsoBarPosition.msoBarTop, System.Type.Missing, true);
- customNavBar.Visible = true;
- // 添加按钮和分组,可以根据需要添加更多的按钮和分组
- AddButton("单选题", "插入单选题");
- AddButton("多选题", "插入多选题");
- AddButton("判断题", "插入判断题");
- AddButton("记忆", "插入记忆");
- AddButton("创造", "插入创造");
- AddButton("应用", "插入应用");
-
- AddButton("答案", "插入答案");
- AddButton("解析", "插入解析");
- AddButton("知识点", "插入知识点");
- }
- private void AddButton(string buttonName, string buttonCaption)
- {
- CommandBarButton button = (CommandBarButton)customNavBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, 1, true);
- button.Style = MsoButtonStyle.msoButtonCaption;
- button.Caption = buttonCaption;
- button.Tag = buttonName;
- button.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(Button_Click);
- }
- private void Button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
- {
- // 在这里根据按钮的 Tag 属性执行相应的操作
- string buttonName = Ctrl.Tag.ToString();
- InsertContent(buttonName);
- }
- private void InsertContent(string content)
- {
- // 获取当前文档的光标位置
- Word.Selection selection = this.Application.Selection;
- // 在光标位置插入内容
- selection.TypeText("{" + content + "}");
- }
- }
- }
|