PictureContentControl Interface

Definition

Represents a document region that displays an image.

public interface class PictureContentControl : IDisposable, Microsoft::Office::Tools::Word::ContentControlBase, System::ComponentModel::IComponent, System::ComponentModel::ISupportInitialize, System::Windows::Forms::IBindableComponent
[System.Runtime.InteropServices.Guid("51d2a6a8-eb22-448f-b239-2e8a3b86ea3e")]
public interface PictureContentControl : IDisposable, Microsoft.Office.Tools.Word.ContentControlBase, System.ComponentModel.IComponent, System.ComponentModel.ISupportInitialize, System.Windows.Forms.IBindableComponent
[<System.Runtime.InteropServices.Guid("51d2a6a8-eb22-448f-b239-2e8a3b86ea3e")>]
type PictureContentControl = interface
    interface ContentControlBase
    interface IBindableComponent
    interface IComponent
    interface IDisposable
    interface ISupportInitialize
Public Interface PictureContentControl
Implements ContentControlBase, IBindableComponent, IComponent, IDisposable, ISupportInitialize
Attributes
Implements

Examples

The following code example adds a new PictureContentControl to the beginning of the document. This example assumes that a file named picture.bmp exists in the %UserProfile%\My Documents folder (for Windows XP and earlier) or the %UserProfile%\Documents folder (for Windows Vista).

This version is for a document-level customization. To use this code, paste it into the ThisDocument class in your project, and call the AddPictureControlAtSelection method from the ThisDocument_Startup method.

private Microsoft.Office.Tools.Word.PictureContentControl pictureControl1;
private System.Drawing.Bitmap bitmap1;

private void AddPictureControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    pictureControl1 = this.Controls.AddPictureContentControl("pictureControl1");

    string imagePath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
    bitmap1 = new System.Drawing.Bitmap(imagePath, true);
    pictureControl1.Image = bitmap1;
}
Dim pictureControl1 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap1 As System.Drawing.Bitmap

Private Sub AddPictureControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    pictureControl1 = Me.Controls.AddPictureContentControl("pictureControl1")
    Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
            "\picture.bmp"
    bitmap1 = New System.Drawing.Bitmap(imagePath, True)
    pictureControl1.Image = bitmap1
End Sub

This version is for an application-level add-in. To use this code, paste it into the ThisAddIn class in your project, and call the AddPictureControlAtSelection method from the ThisAddIn_Startup method.

private Microsoft.Office.Tools.Word.PictureContentControl pictureControl1;
private System.Drawing.Bitmap bitmap1;

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

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    pictureControl1 = vstoDoc.Controls.AddPictureContentControl("pictureControl1");

    string imagePath = System.Environment.GetFolderPath(
        Environment.SpecialFolder.MyDocuments) + "\\picture.bmp";
    bitmap1 = new System.Drawing.Bitmap(imagePath, true);
    pictureControl1.Image = bitmap1;
}
Dim pictureControl1 As Microsoft.Office.Tools.Word.PictureContentControl
Dim bitmap1 As System.Drawing.Bitmap

Private Sub AddPictureControlAtSelection()
    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()
    vstoDoc.Paragraphs(1).Range.Select()
    pictureControl1 = vstoDoc.Controls.AddPictureContentControl("pictureControl1")
    Dim imagePath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments & _
            "\picture.bmp"
    bitmap1 = New System.Drawing.Bitmap(imagePath, True)
    pictureControl1.Image = bitmap1
End Sub

Remarks

A PictureContentControl displays an image. You can specify the image at design time or run time, or users can click this control to select an image to insert in the document.

To get or set the image, use the Image property. By default, users cannot change the image in the PictureContentControl at run time. If you want to enable users to choose the image to display in the control, set the ShowInsertPictureIcon property to true.

Note

This interface is implemented by the Visual Studio Tools for Office runtime. It is not intended to be implemented in your code. For more information, see Visual Studio Tools for Office Runtime Overview.

Content Controls

The PictureContentControl is one of eight types of content controls that you can use to design documents and templates in Microsoft Office Word. Content controls have a user interface (UI) that has controlled input like a form. You can use content controls to prevent users from editing protected sections of the document or template, and you can also bind content controls to a data source. For more information, see Content Controls.

Usage

This documentation describes the version of this type that is used in Office projects that target the .NET Framework 4 or later. In projects that target the .NET Framework 3.5, this type might have different members and the code examples provided for this type might not work. For documentation about this type in projects that target the .NET Framework 3.5, see the following reference section in the Visual Studio 2008 documentation: http://go.microsoft.com/fwlink/?LinkId=160658.

Properties

Application

Gets a Application that represents the current instance of Microsoft Office Word.

Container (Inherited from ContentControlBase)
ContainerComponent (Inherited from ContentControlBase)
Creator

Gets a 32-bit integer that indicates the application in which the PictureContentControl was created.

DefaultDataSourceUpdateMode

Gets or sets the default DataSourceUpdateMode for the ContentControlBase.

(Inherited from ContentControlBase)
ID

Gets a unique number that identifies the content control.

(Inherited from ContentControlBase)
Image

Gets or sets the image that is displayed by the PictureContentControl.

InnerObject

Gets the underlying ContentControl object for the ContentControlBase.

(Inherited from ContentControlBase)
LockContentControl

Gets or sets a value that specifies whether the PictureContentControl can be deleted from the document.

LockContents

Gets or sets a value that specifies whether the contents of the PictureContentControl can be edited.

Parent

Gets the parent of the PictureContentControl.

ParentContentControl

Gets the parent content control of a PictureContentControl that is nested in another content control.

Range

Gets a Range that represents the contents of the PictureContentControl.

ShowInsertPictureIcon

Gets or sets a value that specifies whether to display the UI that users can click to select an image to display in the control at run time.

Tag

Gets or sets a string that you want to associate with the PictureContentControl.

Temporary

Gets or sets a value that specifies whether the PictureContentControl is automatically deleted from the document when the control is edited.

Title

Gets or sets the title of the PictureContentControl.

XMLMapping

Gets an XMLMapping that represents the binding between the PictureContentControl and an element in a custom XML part.

Methods

Copy()

Copies the PictureContentControl from the document to the Clipboard.

Cut()

Removes the PictureContentControl from the document and adds it to the Clipboard.

Delete(Boolean)

Deletes a dynamically created content control from the document and removes it from the ControlCollection in the document.

(Inherited from ContentControlBase)

Events

Added

Occurs after the content control is added to the document.

(Inherited from ContentControlBase)
BindingContextChanged

Occurs when the value of the BindingContext property of the ContentControlBase changes.

(Inherited from ContentControlBase)
ContentUpdating

Occurs just before Microsoft Office Word updates the text in the content control, if the content control is bound to a custom XML part.

(Inherited from ContentControlBase)
Deleting

Occurs just before the content control is deleted from the document.

(Inherited from ContentControlBase)
Entering

Occurs when the user clicks in the content control, or when the cursor is moved into the content control programmatically.

(Inherited from ContentControlBase)
Exiting

Occurs when the user clicks outside the content control, or when the cursor is moved outside the content control programmatically.

(Inherited from ContentControlBase)
StoreUpdating

Occurs just before Microsoft Office Word updates data in a custom XML part that is bound to the content control (that is, after the text in the content control changes).

(Inherited from ContentControlBase)
Validated

Occurs when the content control has been successfully validated.

(Inherited from ContentControlBase)
Validating

Occurs when the contents of the content control are being validated.

(Inherited from ContentControlBase)

Applies to