ControlCollection.AddPictureContentControl أسلوب (ContentControl, String)
قم بإضافة جديد PictureContentControlالتي هو استناداً إلى عنصر تحكم محتوى أصلي في مستند.
مساحة الاسم: Microsoft.Office.Tools.Word
التجميع: Microsoft.Office.Tools.Word (في Microsoft.Office.Tools.Word.dll)
بناء الجملة
'إقرار
Function AddPictureContentControl ( _
contentControl As ContentControl, _
name As String _
) As PictureContentControl
PictureContentControl AddPictureContentControl(
ContentControl contentControl,
string name
)
المعلمات
- contentControl
النوع: Microsoft.Office.Interop.Word.ContentControl
Microsoft.Office.Interop.Word.ContentControlهو أساس الجديد عنصر تحكم.
- name
النوع: System.String
اسم جديد عنصر تحكم.
القيمة المُرجعة
النوع: Microsoft.Office.Tools.Word.PictureContentControl
PictureContentControlالتي تمت إضافتها إلى مستند.
استثناءات
استثناء: | شرط |
---|---|
ArgumentNullException | contentControl هو nullمرجع خالٍ (لا شيء في Visual Basic). -أو- nameهوnullمرجع خالٍ (لا شيء في Visual Basic)أو صفرية الطول. |
ControlNameAlreadyExistsException | عنصر تحكم بنفس الاسم هو موجود بالفعل في ControlCollection. |
ArgumentException | contentControlلا إنشاء? المعرض كتلة (هو Typeخاصية contentControlلا يحتوي القيمة Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlPicture). |
ملاحظات
استخدام ترتيب هو طريقة لإضافة جديد PictureContentControlالتي هو استناداً إلى عنصر تحكم محتوى أصلي في مستند في وقت التشغيل. Th هو هو مفيداً عندما تقوم بإنشاء PictureContentControlفي وقت التشغيل، وكنت ترغب في إعادة إنشاء عنصر التحكم نفسه المرة القادمة مستند هو فتح. لمزيد من المعلومات، راجع إضافة عناصر إلى مستندات Office في وقت التشغيل.
أمثلة
إنشاء مثال التعليمة البرمجية التالية جديدة PictureContentControlلكل صورة أصلية التحكم التي هو في التطبيق.
Th هو الإصدار هو لتخصيص المستوى مستند. إلى استخدام هذا الرمز، قم بلصقه في إلى ThisDocumentالفئة في مشروع، واستدعاء CreatePictureControlFromNativeControlأسلوب من ThisDocument_Startupالأسلوب.
Private pictureControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.PictureContentControl)
Private Sub CreatePictureControlsFromNativeControls()
If Me.ContentControls.Count <= 0 Then
Return
End If
Dim count As Integer = 0
For Each nativeControl As Word.ContentControl In Me.ContentControls
If nativeControl.Type = Word.WdContentControlType.wdContentControlPicture Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.PictureContentControl = _
Me.Controls.AddPictureContentControl(nativeControl, _
"VSTOPictureContentControl" + count.ToString())
pictureControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PictureContentControl> pictureControls;
private void CreatePictureControlFromNativeControl()
{
if (this.ContentControls.Count <= 0)
return;
pictureControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PictureContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in this.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlPicture)
{
count++;
Microsoft.Office.Tools.Word.PictureContentControl tempControl =
this.Controls.AddPictureContentControl(nativeControl,
"VSTOPictureContentControl" + count.ToString());
pictureControls.Add(tempControl);
}
}
}
Th هو الإصدار هو لالمستوى تطبيق الوظيفة الإضافية التي تستهدف .NET Framework 4. إلى استخدام هذا الرمز، قم بلصقه في إلى ThisAddInالفئة في مشروع، واستدعاء CreatePictureControlFromNativeControlأسلوب من ThisAddIn_Startupالأسلوب.
Private pictureControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.PictureContentControl)
Private Sub CreatePictureControlsFromNativeControls()
If Me.Application.ActiveDocument Is Nothing Then
Return
End If
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If vstoDoc.ContentControls.Count <= 0 Then
Return
End If
Dim count As Integer = 0
For Each nativeControl As Word.ContentControl In vstoDoc.ContentControls
If nativeControl.Type = Word.WdContentControlType.wdContentControlPicture Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.PictureContentControl = _
vstoDoc.Controls.AddPictureContentControl(nativeControl, _
"VSTOPictureContentControl" + count.ToString())
pictureControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PictureContentControl> pictureControls;
private void CreatePictureControlFromNativeControl()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (vstoDoc.ContentControls.Count <= 0)
return;
pictureControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PictureContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlPicture)
{
count++;
Microsoft.Office.Tools.Word.PictureContentControl tempControl =
vstoDoc.Controls.AddPictureContentControl(nativeControl,
"VSTOPictureContentControl" + count.ToString());
pictureControls.Add(tempControl);
}
}
}
يلي تعليمات برمجية المثال، يتم إنشاء جديد PictureContentControlلكل عنصر تحكم الصورة الأصلية التي يضيفها مستخدم للتطبيق.
Th هو الإصدار هو لتخصيص المستوى مستند. لاستخدام هذا تعليمات برمجية، لصقه في ThisDocumentالفئة في مشروع الخاص بك. C#، يجب يرفق ThisDocument_PictureContentControlAfterAddمعالج الأحداث إلى ContentControlAfterAddحدث الخاص ThisDocumentفئة.
Private Sub ThisDocument_PictureContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd
If NewContentControl.Type = Word.WdContentControlType.wdContentControlPicture Then
Me.Controls.AddPictureContentControl(NewContentControl, _
"PictureControl" + NewContentControl.ID)
End If
End Sub
void ThisDocument_PictureContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlPicture)
{
this.Controls.AddPictureContentControl(NewContentControl,
"PictureControl" + NewContentControl.ID);
}
}
Th هو الإصدار هو لالمستوى تطبيق الوظيفة الإضافية التي تستهدف .NET Framework 4. لاستخدام هذا تعليمات برمجية، لصقه في ThisAddInالفئة في مشروع الخاص بك. أيضا، يجب يرفق ActiveDocument_PictureContentControlAfterAddمعالج الأحداث إلى ContentControlAfterAddالأحداث من التطبيق النشط.
Private Sub ActiveDocument_PictureContentControlAfterAdd( _
ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean)
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If NewContentControl.Type = Word.WdContentControlType. _
wdContentControlPicture Then
vstoDoc.Controls.AddPictureContentControl(NewContentControl, _
"PictureControl" + NewContentControl.ID)
End If
End Sub
void ActiveDocument_PictureContentControlAfterAdd(
Word.ContentControl NewContentControl, bool InUndoRedo)
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlPicture)
{
vstoDoc.Controls.AddPictureContentControl(NewContentControl,
"PictureControl" + NewContentControl.ID);
}
}
أمن NET Framework.
- الثقة الكاملة للمتصل الفوري. يتعذر استخدام هذا العضو بواسطة التعليمات البرمجية الموثوق بها جزئيًا. لمزيد من المعلومات، راجع باستخدام مكتبات من تعليمات برمجية موثوق بها جزئي.
راجع أيضًَا
المرجع
AddPictureContentControl التحميل الزائد
Microsoft.Office.Tools.Word مساحة الاسم