ApplicationFactory.HasVstoObject(_Document) Yöntem

Tanım

DocumentBelirtilen yerel belge nesnesi için bir konak öğesinin oluşturulup oluşturulmayacağını gösteren bir değer döndürür.

public bool HasVstoObject (Microsoft.Office.Interop.Word._Document document);

Parametreler

document
_Document

Sınanacak yerel belge nesnesi. Bu parametre türünde olsa da _Document , genellikle Document Bu yönteme bir nesne geçirirsiniz.

Döndürülenler

Boolean

trueDocumentbelirtilen nesne için bir konak öğesi oluşturulduysa Document , aksi durumda false .

Örnekler

Aşağıdaki kod örneği, geçerli belgenin ilişkili bir konak öğesine sahip olup olmadığını denetler ve varsa konak öğesini alır. Belgede yönetilen denetimler varsa, örnek, kullanıcıya belgeyi kaydederken yönetilen denetimlerin kalıcı olmadığını bildiren bir uyarı mesajı görüntüler. Bu kod örneği, Microsoft.Office.Interop.Word.ApplicationEvents4_Event.DocumentBeforeSave denetimi gerçekleştirmek için etkinliğin olay işleyicisini kullanır. Bu kodu kullanmak için, ThisAddIn veya öğesini hedefleyen bir Word eklentisi projesindeki sınıfından çalıştırın .NET Framework 4 .NET Framework 4.5 .

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);
        }
    }
}
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

Açıklamalar

Word belgesini kapatmadan veya kaydetmeden önce sürdürmek istediğiniz yönetilen denetimlerin varlığını test etmek için uygulama düzeyi bir eklenti içinde bu yöntemi çağırabilirsiniz. Word belgesinde denetimlerin nasıl kalıcı yapılacağını gösteren bir örnek için bkz. Word eklentisi dinamik denetimler örneği.

Not

documentParametresi Microsoft.Office.Interop.Word._Document , öğesinin üst arabirimi olan türüdür Microsoft.Office.Interop.Word.Document . Bu nedenle, bu yöntem her iki türdeki nesneleri kabul edebilir: Microsoft.Office.Interop.Word._Document ve Microsoft.Office.Interop.Word.Document . Genellikle, bir Word belgesine başvuru yaptığınızda bir kullanırsınız Microsoft.Office.Interop.Word.Document .

Şunlara uygulanır