Udostępnij za pośrednictwem


Button.Locked Property (2007 System)

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.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Property Locked As Boolean
'Usage
Dim instance As Button 
Dim value As Boolean 

value = instance.Locked

instance.Locked = value
[BrowsableAttribute(false)]
public bool Locked { get; set; }
[BrowsableAttribute(false)]
public:
property bool Locked {
    bool get ();
    void set (bool value);
}
public function get Locked () : boolean 
public function set Locked (value : boolean)

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(missing, missing, missing, missing, missing,
         missing, missing, missing, missing, missing, missing, 
         missing, missing, missing, missing, missing);
    Globals.ThisWorkbook.ToggleFormsDesign();
}

.NET Framework Security

See Also

Reference

Button Class

Button Members

Microsoft.Office.Tools.Excel.Controls Namespace