Compartir a través de


Button.Locked Property

Definition

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

public:
 property bool Locked { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool Locked { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Locked : bool with get, set
Public Property Locked As Boolean

Property Value

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

Attributes

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 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();
}
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

Remarks

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

Applies to