ControlCollection.AddPlainTextContentControl Yöntem (ContentControl, String)
Yeni bir ekler PlainTextContentControl belgedeki yerel içerik denetimine dayanır.
Ad alanı: Microsoft.Office.Tools.Word
Derleme: Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll içinde)
Sözdizimi
'Bildirim
Function AddPlainTextContentControl ( _
contentControl As ContentControl, _
name As String _
) As PlainTextContentControl
PlainTextContentControl AddPlainTextContentControl(
ContentControl contentControl,
string name
)
Parametreler
- contentControl
Tür: Microsoft.Office.Interop.Word.ContentControl
Microsoft.Office.Interop.Word.ContentControl Yani yeni denetim için temel oluşturur.
- name
Tür: System.String
Yeni denetimin adı.
Dönüş Değeri
Tür: Microsoft.Office.Tools.Word.PlainTextContentControl
PlainTextContentControl Belgeye eklenmiştir.
Özel Durumlar
Exception | Koşul |
---|---|
ArgumentNullException | contentControlis nullnull başvuru (Visual Basic'te Nothing). -veya- nameolan nullnull başvuru (Visual Basic'te Nothing) veya sıfır uzunlukta. |
ControlNameAlreadyExistsException | Aynı ada sahip bir denetim zaten kullanılıyor ControlCollection. |
ArgumentException | contentControlYapı Taşı Galerisi değil (yani, Type özelliği contentControl değeri yok Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlText). |
Notlar
Yeni bir eklemek için bu yöntemi kullanın PlainTextContentControl temel alan belgedeki yerel içerik denetimine zamanında.Oluşturduğunuzda, bu yararlıdır bir PlainTextContentControl , çalışma zamanında ve aynı denetimi belgenin sonraki açılışında yeniden oluşturun.Daha fazla bilgi için bkz. Office Belgelerine Çalışma Zamanında Denetim Ekleme.
Örnekler
Aşağıdaki kod örneği oluşturur Yeni bir PlainTextContentControl belgedeki her yerel düz metin denetimi için.
Belge düzeyi özelleştirmesinde sürümüdür.Bu kodu kullanmak için içine yapıştırın ThisDocument sınıfı proje ve çağrı CreateTextControlsFromNativeControls yönteminden ThisDocument_Startup yöntem.
Private plainTextControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.PlainTextContentControl)
Private Sub CreatePlainTextControlsFromNativeControls()
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.wdContentControlText Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
Me.Controls.AddPlainTextContentControl(nativeControl, _
"VSTOPlainTextContentControl" + count.ToString())
plainTextControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;
private void CreateTextControlsFromNativeControls()
{
if (this.ContentControls.Count <= 0)
return;
plainTextControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PlainTextContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in this.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
{
count++;
Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
this.Controls.AddPlainTextContentControl(nativeControl,
"VSTOPlainTextContentControl" + count.ToString());
plainTextControls.Add(tempControl);
}
}
}
Bir uygulama düzeyi eklentisi hedefler de için bu sürümü olan .NET Framework 4 veya .NET Framework 4.5.Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı proje ve çağrı CreateTextControlsFromNativeControls yönteminden ThisAddIn_Startup yöntem.
Private plainTextControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.PlainTextContentControl)
Private Sub CreatePlainTextControlsFromNativeControls()
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.wdContentControlText Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.PlainTextContentControl = _
vstoDoc.Controls.AddPlainTextContentControl(nativeControl, _
"VSTOPlainTextContentControl" + count.ToString())
plainTextControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List<Microsoft.Office.Tools.Word.PlainTextContentControl> plainTextControls;
private void CreateTextControlsFromNativeControls()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (vstoDoc.ContentControls.Count <= 0)
return;
plainTextControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.PlainTextContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlText)
{
count++;
Microsoft.Office.Tools.Word.PlainTextContentControl tempControl =
vstoDoc.Controls.AddPlainTextContentControl(nativeControl,
"VSTOPlainTextContentControl" + count.ToString());
plainTextControls.Add(tempControl);
}
}
}
Aşağıdaki kod örneği oluşturur Yeni bir PlainTextContentControl kullanıcı belgeye ekler her yerel düz metin denetimi için.
Belge düzeyi özelleştirmesinde sürümüdür.Bu kodu kullanmak için içine yapıştırın ThisDocument sınıfı projenizdeki.C# [NULL]'ta, ayrıca eklemeniz gerekir ThisDocument_PlainTextContentControlAfterAdd olay işleyicisine ContentControlAfterAdd olayı ThisDocument sınıf.
Private Sub ThisDocument_PlainTextContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd
If NewContentControl.Type = Word.WdContentControlType.wdContentControlText Then
Me.Controls.AddPlainTextContentControl(NewContentControl, _
"PlainTextControl" + NewContentControl.ID)
End If
End Sub
void ThisDocument_PlainTextContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
{
this.Controls.AddPlainTextContentControl(NewContentControl,
"PlainTextControl" + NewContentControl.ID);
}
}
Bir uygulama düzeyi eklentisi hedefler de için bu sürümü olan .NET Framework 4 veya .NET Framework 4.5.Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı projenizdeki.Ayrıca, iliştirmelisiniz ActiveDocument_PlainTextContentControlAfterAdd olay işleyicisine ContentControlAfterAdd etkin belgenin olay.
Private Sub ActiveDocument_PlainTextContentControlAfterAdd( _
ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean)
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If NewContentControl.Type = Word.WdContentControlType. _
wdContentControlText Then
vstoDoc.Controls.AddPlainTextContentControl(NewContentControl, _
"PlainTextControl" + NewContentControl.ID)
End If
End Sub
void ActiveDocument_PlainTextContentControlAfterAdd(
Word.ContentControl NewContentControl, bool InUndoRedo)
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlText)
{
vstoDoc.Controls.AddPlainTextContentControl(NewContentControl,
"PlainTextControl" + NewContentControl.ID);
}
}
.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 Koddan Kitaplıkları Kullanma.
Ayrıca bkz.
Başvuru
AddPlainTextContentControl Fazla Yük
Microsoft.Office.Tools.Word Ad Alanı