ControlCollection.AddDatePickerContentControl Yöntem (ContentControl, String)
Yeni bir ekler DatePickerContentControl koleksiyonuna.Yeni denetimi belgede zaten var olan yerel içerik denetimine bağlıdır.
Ad alanı: Microsoft.Office.Tools.Word
Derleme: Microsoft.Office.Tools.Word (Microsoft.Office.Tools.Word.dll içinde)
Sözdizimi
'Bildirim
Function AddDatePickerContentControl ( _
contentControl As ContentControl, _
name As String _
) As DatePickerContentControl
DatePickerContentControl AddDatePickerContentControl(
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.DatePickerContentControl
DatePickerContentControl 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.wdContentControlDate). |
Notlar
Yeni bir eklemek için bu yöntemi kullanın DatePickerContentControl temel alan belgedeki yerel içerik denetimine zamanında.Oluşturduğunuzda, bu yararlıdır bir DatePickerContentControl , ç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 DatePickerContentControl belgedeki her yerel tarih 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ı CreateDatePickerControlsFromNativeControls yönteminden ThisDocument_Startup yöntem.
Private datePickerControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.DatePickerContentControl)
Private Sub CreateDatePickerControlsFromNativeControls()
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.wdContentControlDate Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.DatePickerContentControl = _
Me.Controls.AddDatePickerContentControl(nativeControl, _
"VSTODatePickerContentControl" + count.ToString())
datePickerControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.DatePickerContentControl> datePickerControls;
private void CreateDatePickerControlsFromNativeControls()
{
datePickerControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.DatePickerContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in this.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlDate)
{
count++;
Microsoft.Office.Tools.Word.DatePickerContentControl tempControl =
this.Controls.AddDatePickerContentControl(nativeControl,
"VSTODatePickerContentControl" + count.ToString());
datePickerControls.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ı CreateDatePickerControlsFromNativeControls yönteminden ThisAddIn_Startup yöntem.
Private datePickerControls As New System.Collections.Generic.List _
(Of Microsoft.Office.Tools.Word.DatePickerContentControl)
Private Sub CreateDatePickerControlsFromNativeControls()
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.wdContentControlDate Then
count += 1
Dim tempControl As Microsoft.Office.Tools.Word.DatePickerContentControl = _
vstoDoc.Controls.AddDatePickerContentControl(nativeControl, _
"VSTODatePickerContentControl" + count.ToString())
datePickerControls.Add(tempControl)
End If
Next nativeControl
End Sub
private System.Collections.Generic.List
<Microsoft.Office.Tools.Word.DatePickerContentControl> datePickerControls;
private void CreateDatePickerControlsFromNativeControls()
{
if (this.Application.ActiveDocument == null)
return;
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
datePickerControls = new System.Collections.Generic.List
<Microsoft.Office.Tools.Word.DatePickerContentControl>();
int count = 0;
foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
{
if (nativeControl.Type == Word.WdContentControlType.wdContentControlDate)
{
count++;
Microsoft.Office.Tools.Word.DatePickerContentControl tempControl =
vstoDoc.Controls.AddDatePickerContentControl(nativeControl,
"VSTODatePickerContentControl" + count.ToString());
datePickerControls.Add(tempControl);
}
}
}
Aşağıdaki kod örneği oluşturur Yeni bir DatePickerContentControl kullanıcı belgeye ekler her yerel tarih 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_DatePickerContentControlAfterAdd olay işleyicisine ContentControlAfterAdd olayı ThisDocument sınıf.
Private Sub ThisDocument_DatePickerContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd
If NewContentControl.Type = Word.WdContentControlType.wdContentControlDate Then
Me.Controls.AddDatePickerContentControl(NewContentControl, _
"DatePickerControl" + NewContentControl.ID)
End If
End Sub
void ThisDocument_DatePickerContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlDate)
{
this.Controls.AddDatePickerContentControl(NewContentControl,
"DatePickerControl" + NewContentControl.ID);
}
}
Bu kodu kullanmak için içine yapıştırın ThisAddIn sınıfı projenizdeki.Ayrıca, iliştirmelisiniz ActiveDocument_DatePickerContentControlAfterAdd olay işleyicisine ContentControlAfterAdd etkin belgenin olay.
Private Sub ActiveDocument_DatePickerContentControlAfterAdd( _
ByVal NewContentControl As Word.ContentControl, _
ByVal InUndoRedo As Boolean)
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
If NewContentControl.Type = Word.WdContentControlType. _
wdContentControlDate Then
vstoDoc.Controls.AddDatePickerContentControl(NewContentControl, _
"DatePickerControl" + NewContentControl.ID)
End If
End Sub
void ActiveDocument_DatePickerContentControlAfterAdd(
Word.ContentControl NewContentControl, bool InUndoRedo)
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
if (NewContentControl.Type == Word.WdContentControlType.wdContentControlDate)
{
vstoDoc.Controls.AddDatePickerContentControl(NewContentControl,
"DatePickerControl" + 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
AddDatePickerContentControl Fazla Yük
Microsoft.Office.Tools.Word Ad Alanı