Поделиться через


How to: Lock Controls to Windows Forms

When you design the user interface (UI) of your Windows application, you can lock the controls once they are positioned correctly, so that you do not inadvertently move or resize them when setting other properties.

Additionally, you can lock and unlock all the controls on the form at once, which is helpful for forms with many controls, or you can unlock individual controls. Once you have placed all the controls where you want them on the form, lock them all in place to prevent erroneous movement.

Note

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Working with Settings.

To lock a control

  • In the Properties window, click the Locked property and select true. (Double-clicking the name toggles the property setting.)

    Alternatively, right-click the control and choose Lock Controls.

    Note

    Locking controls prevents them from being dragged to a new size or location on the design surface. However, you can still change the size or location of controls by means of the Properties window or in code.

To lock all the controls on a form

  • From the Format menu, choose Lock Controls.

    Note

    This command locks the form's size as well, because a form is a control.

To unlock all locked controls on a form

  • From the Format menu, choose Lock Controls.

    All previously locked controls on the form are now unlocked.

To unlock locked controls individually

  • In the Properties window, click the Locked property and select false. (Double-clicking the name toggles the property setting.)

See Also

Reference

Windows Forms Controls by Function

Other Resources

Windows Forms Controls

Arranging Controls on Windows Forms

Labeling Individual Windows Forms Controls and Providing Shortcuts to Them

Controls to Use on Windows Forms