2016-04-02 14 views
1

私は、ボタンのクリックイベントに現在のフォントを保存し、それを2番目のイベントに戻す簡単なc#outlookプラグインを使用しています。System.ArgumentException ActiveInspector.WordEditor.Application.Selection.Fontを復元しています

private void button1_Click(object sender, RibbonControlEventArgs e) 
    { 
     var a = Globals.ThisAddIn; 
     Outlook.Inspector inspector = a.Application.ActiveInspector(); 
     if (inspector.EditorType == OlEditorType.olEditorWord) 
     { 
      Word.Document doc = inspector.WordEditor; 
      Word.Application app = doc.Application; 
      FontArr.Push(app.Selection.Font); 
     } 
    } 

    private void PopFormat_Click(object sender, RibbonControlEventArgs e) 
    { 
     var a = Globals.ThisAddIn; 
     Outlook.Inspector inspector = a.Application.ActiveInspector(); 
     if (inspector.EditorType == OlEditorType.olEditorWord) 
     { 
      Word.Document doc = inspector.WordEditor; 
      Word.Application app = doc.Application; 
      Word.Font f = FontArr.Pop(); 
      app.Selection.Font = f; // at this line exception occurs. 
     } 
    } 

ありがとうございます。

答えて

0

FontクラスのDuplicateプロパティを使用すると、指定されたフォントの文字書式を表す読み取り専用のFontオブジェクトを返すことができます。 Duplicateプロパティを使用すると、複製されたFontオブジェクトのすべてのプロパティの設定を取得できます。 Duplicateプロパティによって返されたオブジェクトを別のFontオブジェクトに割り当てて、それらの設定を一度に適用することができます。複製オブジェクトを別のオブジェクトに割り当てる前に、元のオブジェクトに影響を与えずに複製オブジェクトのプロパティを変更できます。

FontArr.Push(app.Selection.Font.Duplicate); 
+0

Iは次のようにコードを変更し: FontArr.Push(app.Selection.Font.Duplicate)。 うまくいかない:(。 – vmiheer

関連する問題