[英]Event fired when any child inside a form changes (is painted)?
I'm pretty new to C#, Winforms and the Compact Framework and still didn't wrap my mind around it's event system completely.我对 C#、Winforms 和 Compact Framework 还很陌生,但仍然没有完全理解它的事件系统。
I'm looking for a way to add a single event handler to my topmost form, that's called when any of the childs is (re)drawn (or even better, after they're drawn), no matter what type they are.我正在寻找一种方法来将单个事件处理程序添加到我的最顶层表单,当任何子项被(重新)绘制(或者甚至更好,在它们被绘制之后)时调用,无论它们是什么类型。 It's also important that I don't need to add any code to the children's themself.同样重要的是,我不需要向孩子们自己添加任何代码。
In pseudocode it would could look like this在伪代码中它可能看起来像这样
TopMostForm {
anyChildWasReDrawn() {
dostuff();
}
}
Is there any way to do this?有什么办法吗?
Look into handling the Paint handler of your children.考虑处理您孩子的 Paint 处理程序。 For example, in your top most Form you would do something like this:例如,在最顶层的 Form 中,您将执行以下操作:
// each child will call the same method when any of them are redrawn
myChild1.Paint += myChildren_Paint;
myChild2.Paint += myChildren_Paint;
mySomeOtherChild.Paint += myChildren_Paint
The actual handler itself would look something like this:实际的处理程序本身看起来像这样:
void myChildren_Paint(object sender, PaintEventArgs e)
{
dostuff();
}
Note that each child points to this one handler.请注意,每个孩子都指向这个处理程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.