the select range disappear in catched copy event RRS feed

  • Question

  • i have catched word2013's copy event,

    in my custom event handler i do nothing but get the paragraph's style, normally the selection range is rendering with gray backgound color, but after run my custom code, the range's backgound color is nothing, than if switch to another app and back to word again, the range's backgound color showing again. 

    it is real strange.

    public void myCopy(Office.IRibbonControl control, ref bool CancelDefault) {
    	Word.Document doc = Globals.ThisAddIn.Application.ActiveDocument;
    	Word.Range rng = doc.ActiveWindow.Selection.Range;
    	Word.Paragraphs ps = rng.Paragraphs;
    	StringBuilder sb = new StringBuilder();
    	foreach (Word.Paragraph p in ps) {
    		if (DocumentFormatting.IsListHeading(p)) {  
    	//ps = null;
    	//rng = null;
    	//doc = null;
    	CancelDefault = false;

    if comment "DocumentFormatting.IsListHeading(p)" the word behaivor will be fine. so the reason will be in this function:

    public static bool IsListHeading(Word.Paragraph p) {
    	Word.ListFormat lf = p.Range.ListFormat;
    	Word.Style style = (Word.Style)p.get_Style();
    	bool ret = false;
    	if (style.NameLocal.StartsWith(HEADING_NAMELOCAL)) {  
    		Word.ListTemplate lt = style.ListTemplate;
    		if (lt != null) {
    			ret = lt.ListLevels.Count >= 3;
    		//lt = null;
    	//style = null;
    	//lf = null;
    	return ret;
    but i can't find any problem in this function. it desn't have any complex business, it very simple, can anyone help me?

    Thursday, January 16, 2014 10:12 AM


All replies