开发者

How may I prevent the Designer changing control member modifiers to private?

开发者 https://www.devze.com 2023-04-06 19:08 出处:网络
When in the De开发者_JAVA百科signer I change a property of a DataGridViewColumn on which I previously manually changed the modifier to public in the .Designer.cs file, the modifier gets reverted to pr

When in the De开发者_JAVA百科signer I change a property of a DataGridViewColumn on which I previously manually changed the modifier to public in the .Designer.cs file, the modifier gets reverted to private.

Is there any way to prevent this?


I would recommend not changing the designer.

If you really need to have your controls public, I would recommend adding a property to expose them in your code file (not the designer file):

public TextBox MyTextBox { get { return this.textBox1; } }

This will provide public access to the designer generated types without worry of the designer overwriting your changes.

It also makes it much more clear, in the long run, since your public API is defined in your main code file, and not in a second, designer generated file.

That being said, in general, I'd avoid this. Instead of exposing the control itself, I would actually recommend exposing the data that you want to set. Take the text box above - If this text box was a title, I would expose that directly:

public string Title
{  
    get { return this.textBoxTitle.Text; }
    set { this.textBoxTitle.Text = value; }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号