共用方式為


ControlExtensions.AddLinkLabel Method

Definition

Overloads

AddLinkLabel(ControlCollection, Range, String)

Adds a new LinkLabel control to the worksheet at the range specified.

AddLinkLabel(ControlCollection, Double, Double, Double, Double, String)

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

AddLinkLabel(ControlCollection, Range, String)

Adds a new LinkLabel control to the worksheet at the range specified.

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Excel::Controls::LinkLabel ^ AddLinkLabel(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, Microsoft::Office::Interop::Excel::Range ^ range, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.LinkLabel AddLinkLabel (this Microsoft.Office.Tools.Excel.ControlCollection controls, Microsoft.Office.Interop.Excel.Range range, string name);
static member AddLinkLabel : Microsoft.Office.Tools.Excel.ControlCollection * Microsoft.Office.Interop.Excel.Range * string -> Microsoft.Office.Tools.Excel.Controls.LinkLabel
<Extension()>
Public Function AddLinkLabel (controls As ControlCollection, range As Range, 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

A Range that provides the bounds for the control.

name
String

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

Returns

The LinkLabel control that was added to the ControlCollection instance.

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. Multi-area ranges cannot be used. The range should be on the same worksheet as the ControlCollection instance.

Examples

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

private void ExcelAddLinkLabel()
{

    Microsoft.Office.Tools.Excel.Controls.LinkLabel
         linkLabel1 = this.Controls.AddLinkLabel(
         0, 0, 75, 17.25, "linkLabel1");
    linkLabel1.Text = "First Name";
    linkLabel1.LinkColor = Color.Blue;
    linkLabel1.LinkBehavior = LinkBehavior.HoverUnderline;
}
Private Sub ExcelAddLinkLabel()

    Dim LinkLabel1 As Microsoft.Office.Tools.Excel. _
        Controls.LinkLabel = Me.Controls.AddLinkLabel( _
        0, 0, 75, 17.25, "LinkLabel1")
    LinkLabel1.Text = "First Name"
    LinkLabel1.LinkColor = Color.Blue
    LinkLabel1.LinkBehavior = LinkBehavior.HoverUnderline

End Sub

Remarks

The AddLinkLabel method enables you to add LinkLabel objects to the end of the ControlCollection. To remove a LinkLabel that was previously added programmatically, use the Remove method.

The control automatically resizes when the range is resized.

Applies to

AddLinkLabel(ControlCollection, Double, Double, Double, Double, String)

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

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::Office::Tools::Excel::Controls::LinkLabel ^ AddLinkLabel(Microsoft::Office::Tools::Excel::ControlCollection ^ controls, double left, double top, double width, double height, System::String ^ name);
public static Microsoft.Office.Tools.Excel.Controls.LinkLabel AddLinkLabel (this Microsoft.Office.Tools.Excel.ControlCollection controls, double left, double top, double width, double height, string name);
static member AddLinkLabel : Microsoft.Office.Tools.Excel.ControlCollection * double * double * double * double * string -> Microsoft.Office.Tools.Excel.Controls.LinkLabel
<Extension()>
Public Function AddLinkLabel (controls As ControlCollection, left As Double, top As Double, width As Double, height As Double, 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
Double

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

top
Double

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

width
Double

The width of the control in points.

height
Double

The height of the control in points.

name
String

The name of the control.

Returns

The LinkLabel control that was added to the ControlCollection instance.

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 top of the worksheet, and then changes the text to First Name. The code then changes the color of the link to blue and sets the LinkBehavior to HoverUnderline. To use this example, run it from the Sheet1 class in a document-level project.

private void ExcelRangeAddListBox()
{

    Microsoft.Office.Tools.Excel.Controls.ListBox
         listBox1 = this.Controls.AddListBox(
         this.Range["A1", "B6"], "lisBox1");
    listBox1.Items.Add("First Item");
    listBox1.Items.Add("Second Item");
    listBox1.SelectedIndex = 0;
}
Private Sub ExcelRangeAddListBox()

    Dim ListBox1 As Microsoft.Office.Tools.Excel. _
        Controls.ListBox = Me.Controls.AddListBox( _
        Me.Range("A1", "B6"), "ListBox1")

    ListBox1.Items.Add("First Item")
    ListBox1.Items.Add("Second Item")
    ListBox1.SelectedIndex = 0

End Sub

Remarks

The AddLinkLabel method enables you to add LinkLabel objects to the end of the ControlCollection. To remove a LinkLabel control that was previously added programmatically, use the Remove method.

Applies to