Button.Locked 属性

获取或设置一个值,该值指示当工作表受保护时,在设计时能否修改 Button

命名空间:  Microsoft.Office.Tools.Excel.Controls
程序集:  Microsoft.Office.Tools.Excel.v4.0.Utilities(在 Microsoft.Office.Tools.Excel.v4.0.Utilities.dll 中)

语法

声明
<BrowsableAttribute(False)> _
Public Property Locked As Boolean
    Get
    Set
[BrowsableAttribute(false)]
public bool Locked { get; set; }

属性值

类型:System.Boolean
如果当工作表受保护时不能在设计时修改 Button,则为 true;否则为 false。

备注

只有在工作表受保护时,才能锁定 Button。 在设计时不能移动锁定的 Button 或调整其大小。

示例

下面的代码示例向当前工作表中添加两个 Button 控件,并将其中一个按钮的 Locked 属性设置为 true。 然后,该示例保护工作表,并使用 ToggleFormsDesign 方法将 Microsoft Office Excel 置于设计模式。 此时,可以移动未锁定的按钮或调整其大小,但不能移动锁定的按钮或调整其大小。

此示例针对的是文档级自定义项。

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 安全性

请参见

参考

Button 类

Microsoft.Office.Tools.Excel.Controls 命名空间