开发者

WinForms - is there an event captured for changed children controls by a containing panel?

I have a panel and in it are a couple of text boxes, I want to decide if to enable a button (also inside the panel) by the values of the the text boxes.

Is there a predefined event the panel is开发者_运维百科 registered to that captures the inner text-boxes onTextChange event?

Thanks, Shuky


I'd just set up one generic TextBox_TextChanged Event handler that calls my Validate method and then link every TextBox to it, which could be done with a loop.

Maybe something like (not tested):

 foreach (Control ctrl in container.Controls)
 {
   if (ctrl is TextBox)
   {
     ((TextBox)ctrl).TextChanged += new System.EventHandler(TextBox_TextChanged);
   }
 }


Unfortunately you have to do it yourself (subscribe to the event on the text boxes).


No, there isn't (AFAIK). But you can make all of your text boxes use call the same method when the event occurs. If you want to add text boxes dynamically, you might register for the ControlAdded event and in there in turn register on the freshly added textbox.


Unlike in HTML DOM, events in WinForms are not propagated to containing elements, so you'll have to listen to all the events yourself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜