VS2012提示功能看上去很神奇,那我们在Word中也做一个吧!
一、首先在ThisAddIn_Startup中添加DocumentContextOnUpdate事件
Globals.ThisAddIn.Application.ActiveDocument.CommandBars.OnUpdate += DocumentContextOnUpdate;
当用户输入文字内容后触发该事件
二、定义变量
public int CurserPositionX=0;
public int CurserPositionY=0;
public int rangewidth=0;
public int rangeheight=0;
三、事件代码
private void DocumentContextOnUpdate()
{
//得到当前编辑内容的位置(是光标位置,不是鼠标位置)
WordInterop.Range ra = Globals.ThisAddIn.Application.Selection.Range;
Globals.ThisAddIn.Application.ActiveDocument.ActiveWindow.GetPoint(out CurserPositionX,out CurserPositionY, out rangewidth,out rangeheight ,ra);
//创建无标题的非模态的窗口
TempWindowForTest windows= new TempWindowForTest();<