//</Snippet9> //--------------------------------------------------------------------- private void Test1() { //<Snippet10> foreach (object targetControl in this.Controls) { Microsoft.Office.Tools.Word.Bookmark bookMark = targetControl as Microsoft.Office.Tools.Word.Bookmark; if (bookMark != null) { // Do some work with the bookmark here. } } //</Snippet10> //<Snippet2> this.SampleBookmark.Start = this.SampleBookmark.Start - 5; //</Snippet2> //<Snippet3> this.SampleBookmark.End = this.SampleBookmark.End + 5; //</Snippet3> //<Snippet1> Microsoft.Office.Tools.Word.Bookmark firstParagraph; firstParagraph = this.Controls.AddBookmark(this.Paragraphs[1].Range, "FirstParagraph"); //</Snippet1> }
//</Snippet62> //--------------------------------------------------------------------- //<Snippet63> static void BookMarkReplace( ref Microsoft.Office.Tools.Word.Bookmark bookmark, string newText) { //</Snippet63> //<Snippet64> bookmark.Text = newText; }
//</Snippet15> private void ResizeBookmark() { //<Snippet16> Microsoft.Office.Tools.Word.Document vstoDocument = Globals.Factory.GetVstoObject(this.Application.ActiveDocument); vstoDocument.ActiveWindow.View.ShowBookmarks = true; vstoDocument.Paragraphs[1].Range.InsertParagraphBefore(); Word.Range firstParagraph = vstoDocument.Paragraphs[1].Range; firstParagraph.Text = "123456789abcdefghijklmnopqrstuvwxyz"; Microsoft.Office.Tools.Word.Bookmark sampleBookmark = vstoDocument.Controls.AddBookmark(firstParagraph, "bookmark1"); sampleBookmark.Start = sampleBookmark.Start + 5; sampleBookmark.End = sampleBookmark.End - 5; //</Snippet16> }
//</Snippet4> //<Snippet3> void bookmark_BeforeRightClick(object sender, 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 shortcut menu options. if (((Microsoft.Office.Tools.Word.Bookmark)sender).Start == startPosition) { selectedBookmark = (Microsoft.Office.Tools.Word.Bookmark)sender; showBoldButton = true; showItalicButton = true; } }
//</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; } }