16

I'm trying to change properties to a control however it seems as if it's "locked" but in reality, it isn't because when I right-click on the control it shows the control as being unlocked.

I'm using Visual Studio 2005, and I've never worked with a control that seems to be locked as such in the picture provided.

I'd really appreciate a simple explanation and how to resolve this issue so that I can proceed with modifying it.

enter image description here

Gonzo345
  • 1,133
  • 3
  • 20
  • 42
MPaul
  • 2,553
  • 3
  • 20
  • 34
  • What source control system are you using? – Oded Dec 05 '11 at 21:48
  • 1
    not very sure, but probably that control is defined in other file. In other words, you see the Host that holds the control. – Tigran Dec 05 '11 at 21:49
  • It might be attach to a process. Did you pressed F5 to run the project and then switch to VS and trying to edit control. If this is the case you need to stop debugger. – particle Dec 05 '11 at 22:00
  • Are those controls on a UserControl which you've placed on your form? If so then you have to open the UserControl and change the **modifier** property on each of the controls you want to be able to modify. Or you could just modify them on the UserControl itself, if that won't break something else. – Igby Largeman Dec 05 '11 at 22:10

7 Answers7

25

This will happen when you try to design an inherited form and the control(s) on that form are private. The designer observes accessibility modifiers. Go back to the base form and change the Modifiers property of the controls from Private to Protected.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Hi, thanks for your answer. I'm still slightly confused though. What do you mean by the base form? In the image above, the bnvNavigator is a user control which is inherited from Microsoft's BindingNavigator control. I'm assuming by going back to the base form you don't mean alter Microsoft's code? Thanks – MPaul Dec 06 '11 at 21:13
  • I assumed in my answer that you inherited from a form other than the Form class. Project + Add New Item, Windows Forms + Inherited Form. If that's not the case then this answer doesn't match your problem. To make a control embedded in a UserControl editable, you'll need a custom designer. See http://stackoverflow.com/questions/2785376/how-to-bubble-a-controls-features-when-place-in-a-custom-usercontrol/2863807#2863807 I don't understand the screen shot though, doesn't look like a UserControl. – Hans Passant Dec 06 '11 at 21:52
  • @HansPassant That does not seem to do anything for a `TableLayoutPanel`, nor a `FlowLayoutPanel`, which seem to be special. (I'm designing a user control inheriting [not embedding, as in your last comment] another that contains a `TableLayoutPanel`, which remains locked no matter what its accessibility modifier is, `Private`, `Protected` or `Public`.) – Bob Jun 18 '13 at 23:22
  • 1
    Oh, well, [confirmed by MSDN](http://msdn.microsoft.com/en-us/library/ms171689%28v=vs.100%29.aspx): *The TableLayoutPanel control does not support visual inheritance in the Windows Forms Designer. A TableLayoutPanel control in a derived class appears as "locked" at design time.* – Bob Jun 18 '13 at 23:42
  • 1
    If you are using *TableLayoutPanel* in base control and you want to change some layout properties in inherited class insert *TableLayoutPanel* into *Panel*. Of course *Panel* should have *protected* modifier. – rraszewski Feb 05 '14 at 08:16
  • @MPaul I don't forget to rebuild the project after changing the modifiers to protected, that updates the `Designer`. – Simple Aug 29 '22 at 17:10
5

I was suffering exactly the same issue but it was just happening with DevExpress controls.

After some hours of changing modifiers and shooting myself in the feet I found this option on Visual Studio => DevExpress => WinForms Controls vX.X.X => Change Design-Time settings => Enable visual inheritance for Developer Express controls used in Visual Studio.

enter image description here

Gonzo345
  • 1,133
  • 3
  • 20
  • 42
3

Right click on the form and uncheck option "lock controls"

This should help.

Marcin Wieczorek
  • 380
  • 1
  • 12
  • When a control is locked, you can see a little lock at the top left of it. Locking a container also locks all the the controls inside it. – Gabriel GM Dec 05 '11 at 22:27
  • 1
    Sorry, but as I've mentioned before these controls aren't locked. – MPaul Dec 06 '11 at 21:04
0

Go to the base code of the form solution explorer--> formXX --> Dispose(Boolean) and change inheritance line to Inherits System.Windows.Forms.Form

Marwan
  • 57
  • 12
0

If you have form A which name is "Form.cs" in your project, classes from other form's (B, C, D, etc.) will be inheritance class "Form.cs" from your "A"... it should inheritance System.Windows.Forms.Form. Just try change your A forms class name from "Form.cs" to "Form1.cs".

JohnnyBegg43
  • 117
  • 1
  • 10
0

When you are adding a new Inherited form, and want to have all controls unlocked, go to the Form you are Inheriting from, select Designer.cs file and change the controls you want changed to protected. Once that is done, build your solution and then create the inherited form. The controls should become unlocked.

agotfrid
  • 507
  • 5
  • 7
0

Just now I ran into a similar problem after restoring a .CS from a backup directory. The reason for not being able to edit, was that the (back up) file had been created in READ ONLY mode. Once the 'read only' property through explorer was removed and after refreshing the C# project, the problem was solved.