예제 #1
0
        void ThisDocument_BeforeDoubleClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
        {
            Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);

            int numShapes = Application.Selection.InlineShapes.Count;

            if (numShapes > 0)
            {
                InlineShape s = Application.Selection.InlineShapes[1];
                sendViewpointMessage(s.AlternativeText);
            }
        }
예제 #2
0
        //</Snippet5>


        //---------------------------------------------------------------------
        //<Snippet8>
        private void ShowPopupMenu(object sender,
                                   Microsoft.Office.Tools.Word.ClickEventArgs e)
        {
            int startPosition = 0;

            // If bookmarks overlap, get bookmark closest to cursor.
            for (int i = 1; i <= e.Selection.Bookmarks.Count; i++)
            {
                if (e.Selection.Bookmarks[i].Start > startPosition)
                {
                    startPosition = e.Selection.Bookmarks[i].Start;
                }
            }

            // If closest bookmark is the sender, show the popup.
            if (((Microsoft.Office.Tools.Word.Bookmark)sender).Start == startPosition)
            {
                selectedBookmark = (Microsoft.Office.Tools.Word.Bookmark)sender;
                commandBar.ShowPopup();
                e.Cancel = true;
            }
        }
예제 #3
0
        void ThisDocument_BeforeDoubleClick(object sender, Microsoft.Office.Tools.Word.ClickEventArgs e)
        {
            Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
            lineQuestion = new LineQuestion();
            lineQuestion.leftAnswerList = new List<LineLeftAnswer>();
            lineQuestion.rightAnswerList = new List<LineRightAnswer>();
            Word.Selection Sel = this.Application.Selection;
            object charUnit = Word.WdUnits.wdCharacter; //字符移动
            object lineUnit = Word.WdUnits.wdLine; //行移动
            object count = 5;  // 移动次数
            object extend = Word.WdMovementType.wdExtend; //extend对光标移动区域进行扩展选择
            Sel.MoveEnd(charUnit, count);
            Sel.HomeKey(lineUnit, extend);
            if (!string.IsNullOrWhiteSpace(Sel.Range.Text) && Sel.Range.Text.Trim().ToString().Contains("连线"))
            {
                Sel.HomeKey(lineUnit);
                Sel.EndKey(lineUnit, extend);
                string currentParagraphText = Sel.Range.Text; // 获取该行文本内容
                lineQuestion.currentParagraph = 0;
                for (int i = 1; i <= vstoDoc.Paragraphs.Count; i++)
                {
                    if (currentParagraphText.Trim().Equals(vstoDoc.Paragraphs[i].Range.Text.Trim().ToString()))
                    {
                        // 获取该行在文档中的段落数
                        lineQuestion.currentParagraph = i;
                        break;
                    }
                }
                if (lineQuestion.currentParagraph != 0)
                {
                    // 获取每一道连线题的连线行总数
                    lineQuestion.answerCount = validParagraphs(lineQuestion.currentParagraph);
                }
                if (lineQuestion.answerCount != 0)
                {

                    for (int i = 1; i <= lineQuestion.answerCount; i++)
                    {
                        // 获取连线行内容
                        string paragraphText = vstoDoc.Paragraphs[lineQuestion.currentParagraph + i].Range.Text.ToString();

                        // 操作连线行左侧
                        string leftAnswerStr = paragraphText.Substring(0, paragraphText.IndexOf(" "));
                        LineLeftAnswer lla = new LineLeftAnswer();
                        lla.leftIndex = leftAnswerStr.Substring(0, leftAnswerStr.IndexOf("."));
                        lla.leftAnswer = leftAnswerStr.Substring(leftAnswerStr.IndexOf(".") + 1);
                        lineQuestion.leftAnswerList.Add(lla);

                        // 操作连线行左侧
                        string rightAnswerStr = paragraphText.Substring(paragraphText.LastIndexOf(" ") + 1);
                        LineRightAnswer lra = new LineRightAnswer();
                        lra.rightIndex = rightAnswerStr.Substring(0, rightAnswerStr.IndexOf("."));
                        lra.rightAnswer = rightAnswerStr.Substring(rightAnswerStr.IndexOf(".") + 1);
                        lineQuestion.rightAnswerList.Add(lra);
                    }
                }

                if(lineQuestion != null)
                {
                    LineSelectAnswerForm answerForm = new LineSelectAnswerForm(lineQuestion) { StartPosition = FormStartPosition.CenterParent };
                    answerForm.AnswerEvent += (str) => { answer = str; }; // 获得答案
                    answerForm.ShowDialog();

                    Word.Document document = this.Application.ActiveDocument;
                    string originalTxt = document.Paragraphs[lineQuestion.currentParagraph].Range.Text.ToString();
                    originalTxt = originalTxt.Substring(0, originalTxt.IndexOf("]", 5) + 1);
                    string currentTxt = originalTxt + answer + "\n";
                    answer = null;
                    document.Paragraphs[lineQuestion.currentParagraph].Range.Text = currentTxt; // 替换原段落的内容
                }

            }
        }