Compartilhar via


Button.Locked Property

Gets or sets a value that indicates whether the Button can be modified at design time when the sheet is protected.

Namespace:  Microsoft.Office.Tools.Excel.Controls
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Property Locked As Boolean
[BrowsableAttribute(false)]
public bool Locked { get; set; }

Property Value

Type: System.Boolean
true if the Button cannot be modified at design time when the sheet is protected; otherwise, false.

Remarks

A Button can only be locked when the sheet is protected. A locked Button cannot be moved or resized at design time.

Examples

The following code example adds two Button controls to the current worksheet and sets the Locked property of one of the buttons to true. The example then protects the worksheet and uses the ToggleFormsDesign method to place Microsoft Office Excel into design mode. At this point, the unlocked button can be moved and resized, but the locked button cannot be moved or resized.

This example is for a document-level customization.

Private Sub TestLockedControl()

    Dim LockedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B2", "C3"), "LockedButton")
    LockedButton.Locked = True
    LockedButton.Text = "Locked button" 

    Dim UnlockedButton As Microsoft.Office.Tools.Excel.Controls.Button = _
        Me.Controls.AddButton(Me.Range("B6", "C7"), "UnlockedButton")
    UnlockedButton.Locked = False
    UnlockedButton.Text = "Unlocked button" 

    Me.Protect()
    Globals.ThisWorkbook.ToggleFormsDesign()
End Sub
private void TestLockedControl()
{
    Microsoft.Office.Tools.Excel.Controls.Button lockedButton =
            this.Controls.AddButton(this.Range["B2", "C3"],
            "lockedButton");
    lockedButton.Locked = true;
    lockedButton.Text = "Locked button";

    Microsoft.Office.Tools.Excel.Controls.Button unlockedButton =
            this.Controls.AddButton(this.Range["B6", "C7"],
            "unlockedButton");
    unlockedButton.Locked = false;
    unlockedButton.Text = "Unlocked button";

    this.Protect();
    Globals.ThisWorkbook.ToggleFormsDesign();
}

.NET Framework Security

See Also

Reference

Button Class

Microsoft.Office.Tools.Excel.Controls Namespace