简体   繁体   中英

C#, editing in UserControl doesn't inherit graphics

I have a custom control, MyControl, that inherits from UserControl.

If i change MyControl graphic proprerties(like ForeColor, backgroundImage, etc) i aspect this will be applied to all my instances of MyControl, but is not.

Why?

EDIT

I think the problem is that image are stored inside resx file of Control that contains MyControl (example a Form). When this line is called, the old image is applied.

resources.ApplyResources(this.myControl1, "myControl1");

So when i make changes in MyControl designer class, this are not applied to myControl1 instance. Unfortunately this line was autogenerated in designer of Form.

Thanks

您应该在MyControl的构造函数中或控件的设计者(而不是Form)中进行设置(例如,更改背景图像和内容)。

Well of course it doesn't. When you add the control to a form, it grabs the properties and adds code in form.designer.cs, setting them. Change them in the form designer, those chamges get persisted in .designer.cs

If you then change the control itself, to pick up those changes you'd have to remove and add it again.

The only way round that is for the properties not to be configurable in the designer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM