다음을 통해 공유


ControlExtensions.AddLinkLabel Method

Definition

Overloads

AddLinkLabel(ControlCollection, Range, Single, Single, String)

Adds a new LinkLabel control to the document in the specified size and location.

AddLinkLabel(ControlCollection, Single, Single, Single, Single, String)

Adds a new LinkLabel control to the document in the specified size and location.

AddLinkLabel(ControlCollection, Range, Single, Single, String)

Adds a new LinkLabel control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::LinkLabel ^ AddLinkLabel(Microsoft::Office::Tools::Word::ControlCollection ^ controls, Microsoft::Office::Interop::Word::Range ^ range, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.LinkLabel AddLinkLabel (this Microsoft.Office.Tools.Word.ControlCollection controls, Microsoft.Office.Interop.Word.Range range, float width, float height, string name);
static member AddLinkLabel : Microsoft.Office.Tools.Word.ControlCollection * Microsoft.Office.Interop.Word.Range * single * single * string -> Microsoft.Office.Tools.Word.Controls.LinkLabel
<Extension()>
Public Function AddLinkLabel (controls As ControlCollection, range As Range, width As Single, height As Single, name As String) As LinkLabel

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

range
Range

The location of the control.

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

The name of the control that can be used to index the control in the ControlCollection instance.

Returns

The control that was added to the document.

Exceptions

The name or range argument is null, or the name argument has zero length.

A control with the same name is already in the ControlCollection instance.

The range that was specified is not valid.

Examples

The following code example adds a LinkLabel control to the first paragraph in the document, and then changes the text to First Name. The code then changes the color of the link to blue and sets the LinkBehavior property to the HoverUnderline value of the LinkBehavior enumeration. To use this example, run it from the ThisDocument class in a document-level project.

private void WordRangeAddLinkLabel()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.LinkLabel
         linkLabel1 = this.Controls.AddLinkLabel(
         this.Paragraphs[1].Range, 75, 17.25F, "linkLabel1");
    linkLabel1.Text = "First Name";
    linkLabel1.LinkColor = Color.Blue;
    linkLabel1.LinkBehavior = LinkBehavior.HoverUnderline;
}
Private Sub WordRangeAddLinkLabel()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim LinkLabel1 As Microsoft.Office.Tools.Word.Controls. _
        LinkLabel = Me.Controls.AddLinkLabel(Me.Paragraphs(1). _
        Range, 75, 17.25F, "LinkLabel1")
    LinkLabel1.Text = "First Name"
    LinkLabel1.LinkColor = Color.Blue
    LinkLabel1.LinkBehavior = LinkBehavior.HoverUnderline
End Sub 

Remarks

This method enables you to add LinkLabel objects to the end of the ControlCollection.

To remove a LinkLabel that was added programmatically, use the Remove method.

Applies to

AddLinkLabel(ControlCollection, Single, Single, Single, Single, String)

Adds a new LinkLabel control to the document in the specified size and location.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Word::Controls::LinkLabel ^ AddLinkLabel(Microsoft::Office::Tools::Word::ControlCollection ^ controls, float left, float top, float width, float height, System::String ^ name);
public static Microsoft.Office.Tools.Word.Controls.LinkLabel AddLinkLabel (this Microsoft.Office.Tools.Word.ControlCollection controls, float left, float top, float width, float height, string name);
static member AddLinkLabel : Microsoft.Office.Tools.Word.ControlCollection * single * single * single * single * string -> Microsoft.Office.Tools.Word.Controls.LinkLabel
<Extension()>
Public Function AddLinkLabel (controls As ControlCollection, left As Single, top As Single, width As Single, height As Single, name As String) As LinkLabel

Parameters

controls
ControlCollection

The collection to add the control to. Do not supply this parameter yourself. When you call this method on the collection returned by the Controls property (in an application-level project) or the Controls property (in a document-level project), this parameter is supplied automatically.

left
Single

The distance in points between the left edge of the control and the left edge of the document.

top
Single

The distance in points between the top edge of the control and the top edge of the document.

width
Single

The width of the control in points.

height
Single

The height of the control in points.

name
String

The name that can be used to index the control in the ControlCollection instance.

Returns

The control that was added to the document.

Exceptions

The name argument is null or has zero length.

A control with the same name is already in the ControlCollection instance.

Examples

The following code example adds a LinkLabel control to the start of the document, and then changes the text to First Name. The code then changes the color of the link to blue and sets the LinkBehavior property to HoverUnderline value of the LinkBehavior enumeration. To use this example, run it from the ThisDocument class in a document-level project.

private void WordAddLinkLabel()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Controls.LinkLabel
         linkLabel1 = this.Controls.AddLinkLabel(
         0, 0, 75, 17.25F, "linkLabel1");
    linkLabel1.Text = "First Name";
    linkLabel1.LinkColor = Color.Blue;
    linkLabel1.LinkBehavior = LinkBehavior.HoverUnderline;
}
Private Sub WordAddLinkLabel()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim LinkLabel1 As Microsoft.Office.Tools.Word.Controls. _
        LinkLabel = Me.Controls.AddLinkLabel(0, 0, 75, 17.25F, _
        "LinkLabel1")
    LinkLabel1.Text = "First Name"
    LinkLabel1.LinkColor = Color.Blue
    LinkLabel1.LinkBehavior = LinkBehavior.HoverUnderline
End Sub 

Remarks

This method enables you to add LinkLabel objects to the end of the ControlCollection.

To remove a LinkLabel that was added programmatically, use the Remove method.

Applies to