ApplicationFactory.HasVstoObject Yöntem
Gösteren bir değeri döndürür olup bir Microsoft.Office.Tools.Word.Document ana madde için belirtilen özgün belge nesnesi oluşturuldu.
Ad alanı: Microsoft.Office.Tools.Word
Derleme: Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll içinde)
Sözdizimi
'Bildirim
Function HasVstoObject ( _
document As _Document _
) As Boolean
bool HasVstoObject(
_Document document
)
Parametreler
- document
Tür: Microsoft.Office.Interop.Word._Document
Test etmek için özgün belge nesnesi.Bu parametre türü olmasına rağmen Microsoft.Office.Interop.Word._Document, genellikle geçmesi bir Microsoft.Office.Interop.Word.Document bu yöntemi nesne.
Dönüş Değeri
Tür: System.Boolean
true yoksa bir Microsoft.Office.Tools.Word.Document ana maddesi oluşturulan belirtilen için Microsoft.Office.Interop.Word.Document nesne; Aksi halde, false.
Notlar
Bir uygulama düzeyinde kapatmayı ya da Word belgesi kaydetme önce kalıcı olmasını istediğiniz yönetilen denetimleri varlığını sınamak için eklenti de, bu yöntemi çağırın.Bir Word belgesi içindeki denetimleri kalıcı gösterilmiştir bir örnek için bkz: Word Add-In Dynamic Controls Sample.
[!NOT]
document Parametresi türü Microsoft.Office.Interop.Word._Document, üst arabiriminin olduğu Microsoft.Office.Interop.Word.Document.Bu nedenle, bu yöntem her iki türdeki nesneleri kabul edebilirsiniz: Microsoft.Office.Interop.Word._Document ve Microsoft.Office.Interop.Word.Document.Genellikle, bir Word belgesini başvuru yaptığınızda, kullandığınız bir Microsoft.Office.Interop.Word.Document.
Örnekler
Aşağıdaki kod örneği ilişkili ana öğenin geçerli belgede var ise, ana öğe alır olup olmadığını denetler.Yönetilen denetimleri belgesinde mevcutsa, bu örnek kullanıcı yönetilen denetimleri belge kaydedilirken kalıcı olmayacak olduğunu bildiren bir uyarı iletisi görüntüler.Bu kod örneği, olay işleyicisi kullanır DocumentBeforeSave olay denetimi gerçekleştirme.Çalıştır buradan bu kodu kullanmak için ThisAddIn Word eklentisi sınıfında hedefleyen proje .NET Framework 4.
Private Sub Application_DocumentBeforeSave( _
ByVal Doc As Microsoft.Office.Interop.Word.Document, _
ByRef SaveAsUI As Boolean, _
ByRef Cancel As Boolean) Handles Application.DocumentBeforeSave
If Globals.Factory.HasVstoObject(Doc) = True Then
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Doc)
If vstoDoc.Controls.Count > 0 Then
System.Windows.Forms.MessageBox.Show( _
"The VSTO controls are not persisted when you save this document.", _
"Controls Persistence", _
System.Windows.Forms.MessageBoxButtons.OK, _
System.Windows.Forms.MessageBoxIcon.Warning)
End If
End If
End Sub
void Application_DocumentBeforeSave(
Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI,
ref bool Cancel)
{
if (Globals.Factory.HasVstoObject(Doc) == true)
{
Document vstoDoc = Globals.Factory.GetVstoObject(Doc);
if (vstoDoc.Controls.Count > 0)
{
System.Windows.Forms.MessageBox.Show(
"The VSTO controls are not persisted when you save this document.",
"Controls Persistence",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning);
}
}
}
.NET Framework Güvenliği
- Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. Kısmen güvenilen kod kitaplıklarını kullanma.
Ayrıca bkz.
Başvuru
Microsoft.Office.Tools.Word Ad Alanı