如何清除VSTO中的突出显示

时间:2018-05-14 11:46:30

标签: c# ms-word vsto word-addins word-automation

我正在import UIKit @IBDesignable class CardBoardView: UIView { public lazy var grid = Grid(layout: .aspectRatio(values.ratio), frame: self.bounds) var cards = [CardSubview]() public var cells = 12 private var selectedCards = [Int]() private var deck = gameDeck(numbersOfCards: 81) private var indexOfCards = 0 let values = Values() var index1 = 1 var index2 = 1 var index3 = 1 var index4 = 1 struct Values { public let ratio:CGFloat = 2.0 public let insetByX:CGFloat = 2.0 public let insetByY:CGFloat = 2.0 public let allAvailableCards = 81 } @objc private func tab (recognizer: UITapGestureRecognizer) { switch recognizer.state { case .ended: if let card = recognizer.view as? CardSubview { card.isSelected = !card.isSelected if card.isSelected == true { selectedCards.append(cards.index(of: card)!) if selectedCards.count == 3 { if isSet(indexes: selectedCards) == true { selectedCards.forEach { index in cards[index].removeFromSuperview() cards.remove(at: index) } } else { selectedCards.forEach{ index in cards[index].isSelected = false } selectedCards.removeAll() } } } else if card.isSelected == false { if selectedCards.contains(cards.index(of: card)!) { selectedCards.remove(at: selectedCards.index(of: cards.index(of:card)!)!) } } } default: break } } private func isSet(indexes: [Int]) -> Bool { return deck.isSet(arrayOfIndexes: indexes) } private func nextIndex() { index1+=1 if index1==4 { index1=1 index2+=1 if index2==4 { index2=1 index3+=1 if index3==4 { index3=1 index4+=1 if index4==4 { index4=1 } } } } } override func layoutSubviews() { super.layoutSubviews() grid.cellCount = cells for index in 0...80 { cards.append(CardSubview()) cards[index].index1=index1 cards[index].index2=index2 cards[index].index3=index3 cards[index].index4=index4 nextIndex() } for index in 0..<grid.cellCount{ let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(tab)) cards[indexOfCards].addGestureRecognizer(tapRecognizer) cards[indexOfCards].frame = grid[index]!.insetBy(dx: values.insetByX, dy: values.insetByY) addSubview(cards[indexOfCards]) indexOfCards+=1 } } } 中开发word addin。我使用c#方法突出显示找到的搜索字词。 (有关背景信息,请参阅Find and Highlight issue in word addin)。

我使用Find方法,但我想多次使用它。但是,之前搜索中突出显示的单词仍然突出显示。

如何在运行方法之前清除旧的突出显示范围?

Find.Execute()

1 个答案:

答案 0 :(得分:0)

要从文档正文中删除突出显示:

Word.Document doc = Globals.ThisAddin.Application.ActiveDocument.InnerObject;
doc.Content.HighlightColorIndex = Word.WdColorIndex.wdNoHighlight;
//Now perform the Find