다음을 통해 공유


ControlCollection.AddPictureContentControl 메서드 (Range, String)

PictureContentControl 컨트롤을 문서의 지정된 범위에 추가합니다.

네임스페이스:  Microsoft.Office.Tools.Word
어셈블리:  Microsoft.Office.Tools.Word(Microsoft.Office.Tools.Word.dll)

구문

‘선언
Function AddPictureContentControl ( _
    range As Range, _
    name As String _
) As PictureContentControl
PictureContentControl AddPictureContentControl(
    Range range,
    string name
)

매개 변수

반환 값

형식: Microsoft.Office.Tools.Word.PictureContentControl
문서에 추가된 PictureContentControl입니다.

예외

예외 상황
ArgumentNullException

name이 nullNull 참조(Visual Basic의 경우 Nothing)이거나 길이가 0인 경우

ControlNameAlreadyExistsException

이름이 같은 컨트롤이 ControlCollection에 이미 있는 경우

설명

이 메서드를 사용하여 런타임에 문서의 지정된 범위에 새 PictureContentControl을 추가합니다. 자세한 내용은 런타임에 Office 문서에 컨트롤 추가을 참조하십시오.

예제

다음 코드 예제에서는 문서의 시작 부분에 새 PictureContentControl을 추가합니다. 이 예제에서는 picture.bmp라는 파일이 %UserProfile%\My Documents 폴더(Windows XP 이전 버전의 경우) 또는 %UserProfile%\Documents 폴더(Windows Vista의 경우)에 있다고 가정합니다.

이 버전은 문서 수준 사용자 지정을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 ThisDocument 클래스에 해당 코드를 붙여넣고 ThisDocument_Startup 메서드에서 AddPictureControlAtRange 메서드를 호출합니다.

Dim pictureControl2 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap2 As System.Drawing.Bitmap

Private Sub AddPictureControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    pictureControl2 = Me.Controls.AddPictureContentControl(Me.Paragraphs(1).Range, "pictureControl2")
    Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
            "\picture.bmp"
    bitmap2 = New System.Drawing.Bitmap(imagePath, True)
    pictureControl2.Image = bitmap2
End Sub
private Microsoft.Office.Tools.Word.PictureContentControl pictureControl2;
private System.Drawing.Bitmap bitmap2;

private void AddPictureControlAtRange()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    pictureControl2 = this.Controls.AddPictureContentControl(
        this.Paragraphs[1].Range, "pictureControl2");

    string imagePath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
    bitmap2 = new System.Drawing.Bitmap(imagePath, true);
    pictureControl2.Image = bitmap2;
}

이 버전은 .NET Framework 4를 대상으로 하는 응용 프로그램 수준 추가 기능을 위한 것입니다. 이 코드를 사용하려면 프로젝트의 ThisAddIn 클래스에 해당 코드를 붙여넣고 ThisAddIn_Startup 메서드에서 AddPictureControlAtRange 메서드를 호출합니다.

Dim pictureControl2 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap2 As System.Drawing.Bitmap

Private Sub AddPictureControlAtRange()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    pictureControl2 = vstoDoc.Controls.AddPictureContentControl( _
        vstoDoc.Paragraphs(1).Range, "pictureControl2")
    Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
            "\picture.bmp"
    bitmap2 = New System.Drawing.Bitmap(imagePath, True)
    pictureControl2.Image = bitmap2
End Sub
private Microsoft.Office.Tools.Word.PictureContentControl pictureControl2;
private System.Drawing.Bitmap bitmap2;

private void AddPictureControlAtRange()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    pictureControl2 = vstoDoc.Controls.AddPictureContentControl(
        vstoDoc.Paragraphs[1].Range, "pictureControl2");

    string imagePath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
    bitmap2 = new System.Drawing.Bitmap(imagePath, true);
    pictureControl2.Image = bitmap2;
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

ControlCollection 인터페이스

AddPictureContentControl 오버로드

Microsoft.Office.Tools.Word 네임스페이스

기타 리소스

런타임에 Office 문서에 컨트롤 추가

호스트 컨트롤의 도우미 메서드

방법: Word 문서에 콘텐츠 컨트롤 추가