自定义组件未更新 [英] Custom Component didn't Update

查看:92
本文介绍了自定义组件未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个文本框自定义控件。

在控件中,我更改了前景色和背景色。

当我在窗体中使用控件并运行它时,一切看起来很完美。

但是当我更改自定义控制代码时,表单内的文本框没有改变。

这是正常的吗?

我有什么办法可以更新表格中的控件,所以我不需要删除并读取控件吗?



另外:

当我更改fore / backcolor旁边的多行或其他属性并重建项目时,我的表单中的文本框就像旧的一样。

I create a textbox custom control.
Inside the control, I change the forecolor and backcolor.
When I use the control in a form and run it, everything seems perfect.
But when I change the custom control code, the textbox inside the form didn't change.
Is this normal?
Is there anything I can do to update the control inside the form so I don't need to delete and readd the control?

Addition :
When I change the multiline or other properties beside fore/backcolor and rebuild the project, the textbox inside my form is just like the old one.

推荐答案

更改后颜色,在文本框的代码中调用this.Invalidate()。



在设计师中,事情并不像他们在运行时那样发生。你需要强迫一些事情发生。调用Invalidate会强制重绘文本框。
After changing the color, call this.Invalidate() inside the code for the text box.

In the designer things don't happen like they do when it is running. You need to force some things to happen. Calling Invalidate forces the textbox to be redrawn.


看起来您遇到了Designer和Default值的问题。将DefaultValue属性添加到属性的实现中,因此当Designer具有标准值时,Designer不会在Form1.Designer.cs文件中为该属性写入条目。

您可以在 http://上查看示例stackoverflow.com/questions/11929496/overriding-the-defaultvalueattribute-of-an-inherited-property [ ^ ] - 但也有限制。
Looks like you hit a problem with the Designer and Default values. Add the DefaultValue attribute to your implementation of the property, thus the Designer will not write an entry for the property in the Form1.Designer.cs file when it has its standard value.
You can see an example at http://stackoverflow.com/questions/11929496/overriding-the-defaultvalueattribute-of-an-inherited-property[^] - but also the limitations.


这篇关于自定义组件未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆