Sunday, October 18, 2009

Why can't I edit my WinForms control?

Last week, one of my developers came to me with a strange question. He had to change one of our existing WinForms views. There was one label that he couldn't edit. When he tried to access this control in code, the Intellisense would not show up. I came by to have a look.

As I found out, a control has a GenerateMember property. If you change this property to false, the control code is generated by the designer as a local member of the InitializeComponent() method and therefore is not accessable outside the context of this method. And that was exactly the problem he had. He accidently changed the default value from true to false. By changing it back, a class level member is generated and he could access the control again from other places.

No comments: