나는 그것을 마침내 발견했습니다. 또한 실제 Word 문서 (Microsoft.Office.Tools.Word.Document) 개체에 이벤트 처리기를 연결해야했습니다.
this.Application.DocumentBeforeClose += new Interop.Word.ApplicationEvents4_DocumentBeforeCloseEventHandler(Application_DocumentBeforeClose);
Application_DocumentBeforeClose(Interop.Word.Document document, ref bool Cancel)
{
// Documents is a list of the active Tools.Word.Document objects.
if (this.Documents.ContainsKey(document.FullName))
{
// I set the tag to true to indicate I want to cancel.
this.Document[document.FullName].Tag = true;
}
}
public MyDocument()
{
// Tools.Office.Document object
doc.BeforeClose += new CancelEventHandler(WordDocument_BeforeClose);
}
private void WordDocument_BeforeClose(object sender, CancelEventArgs e)
{
Tools.Word.Document doc = sender as Tools.Word.Document;
// This is where I now check the tag I set.
bool? cancel = doc.Tag as bool?;
if (cancel == true)
{
e.Cancel = true;
}
}
그래서 논리가 응용 프로그램 클래스 코드에서 이루어집니다 내 응용 프로그램의 모든 때문에, 내가 필요로 내 MyDocument에 표시 할 수있는 방법을 (Tools.Word.Document 및 Interop.Word.Document은 ... 나에게 두통 제공) close 이벤트를 취소하려는 클래스 이벤트. 그렇기 때문에 태그 객체를 사용하여 플래그를 저장합니다.
조금만 걸어 나가십시오. 논리적으로 "취소"를 false로 설정하면 "취소"기능이 작동해서는 안되며 true로 설정하면 제대로 작동합니다. 네가 한 말은 취소를 참으로 설정 한거야. – Steven
@Steven 설정을 true로 취소한다는 것은 "예, 닫기 이벤트를 취소하십시오"를 의미합니다. Joe가 취소를 true로 설정했지만 문서가 닫히면 문제가있는 것처럼 보입니다. – phoog
@phoog 아, 고맙습니다. – Steven