This event isn't suitable because it the designer adds controls to panels before adding the panel to form its on. This results in ParentChanged firing before it's possible to follow the Parent property to the form object. – Dan Neely Nov 23 '10 at 19:52 When the parent gets set, you could walk up the current parent chain and hook the ParentChanged events of each parent along the way.
That way you'll know when the parent changes for any ancestor. When a parent changes, unhook all you ParentChanged handlers (to do this, you'd have to stored all hooked controls in a list in the previous step) and then do the ancestor walk again. – Mike Dour Nov 23 '10 at 21:57 1 I was able to get that to work.
Since I'm not doing anything that would cause ParentChanged to fire more than once per control I just hook the same code to the topmost control in the Parent chain if it's not the Form object I'm looking for. – Dan Neely Nov 24 '10 at 18:57 That makes sense. Glad I was able to help.
– Mike Dour Nov 24 '10 at 20:02.
Add a new MyForm object in MyControl MyForm pForm; pass a MyForm reference to MyControl when create it: MyControl newControl = new MyControl(this); then register ControlAdded event of your MyForm object pForm. ControlAdded+=new ControlEventHandler(pForm_ControlAdded); Based on your code, it should looks something like: class MyForm : IMyForm { private MethodThatAddsAControl() //includes includes InitializeComponent as well as several others called at later { MyControl newControl = new MyControl(this); //other initialization as needed this.Controls. Add(newControl); //this will raise MyControl ::pForm_ControlAdded } } class MyControl : Control { Myform pForm; public MyControl(MyForm ff) { InitializeComponent(); pForm=ff; pForm.
ControlAdded+=new ControlEventHandler(pForm_ControlAdded); } } EDIT: for the MyControl you want add to a panel, just pass the panel's reference to MyControl: class MyForm : IMyForm { private MethodThatAddsAControl() //includes includes InitializeComponent as well as several others called at later { //create a MyControl object and add it to MyForm MyControl newControl = new MyControl(this); //other initialization as needed this.Controls. Add(newControl); //this will raise MyControl::pForm_ControlAdded //create a MyControl object and add it to MyPanel1 MyControl newControl = new MyControl(MyPanel1); //pass panel reference MyPanel1.Controls. Add(newControl); //this will raise MyControl::pPanel_ControlAdded } } class MyControl : Control { //// for control added to Form Myform pForm; public MyControl(MyForm ff) { InitializeComponent(); pForm=ff; pForm.
ControlAdded+=new ControlEventHandler(pForm_ControlAdded); } ///now for control added to panel MyPanel pPanel; public MyControl(MyPanel pp) { InitializeComponent(); pPanel=pp; pPanel. ControlAdded+=new ControlEventHandler(pPanel_ControlAdded); } }.
– Dan Neely Nov 23 '10 at 16:57 yes, if I understand your comments correctly – Bolu Nov 23 '10 at 17:03 I don't think your edit will work. I need the IMyForm, and because the VS designer adds controls to panels before adding the panel to the form when pPanel_ControlAdded is called I don't have a way to get the form. – Dan Neely Nov 24 '10 at 14:43 Actually it will if I modify it to pass the panel and the form it will be added to.
The designer is bombing at the moment, and the error appears to be that it needs a parameterless constructor, which unless I'm missing something kills your idea. – Dan Neely Nov 24 '10 at 15:36 Can you copy&paste error messages? – Bolu Nov 24 '10 at 16:16.
This article explains the method: ondotnet.com/pub/a/dotnet/2002/04/15/eve....
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.