Erik Porter's ControlArray

I had a need to set the dirty bit for a user control or form and I started looking for a common event that all controls shared like "Changed" or "Modified".  Not having found such a thing, I started searching and I came across Erik Porter's ControlArray (for which he was selected Code Hero BTW).   Now I had to make some modifications to his control (and port it over to C# because my VB.NET skills are non-existent)  but the end result was I had a component that fit my needs with room to grow!

I changed the following:  

  • Ported to C#  (due to my own ignorance...)
  • Added a "Modified" Event
  • Changed specific events (like TextChanged) to raise this new Modified Event.
  • Looked for specific controls (like ListView) and added those specific events to the control.
  • TODO: Dynamically add all controls on a Form to the ControlArray.
  • TODO:  Add support for more specific events raised by controls that inherit from Windows.Forms.Control.
The end result is, with the following code, I can check to see if any of the controls on the form changed with one event. 

controlArray = new  ControlArray();
controlArray.Controls.Add(this
.textBox3);
controlArray.Controls.Add(this
.checkBox1);
controlArray.Controls.Add(this.listView1);

controlArray.Modified += new EventHandler(this.ControlArray_Changed);

Very Cool.  Thanks Erik!

p.s.  I will try to get my bits posted after I get a chance to work on it this weekend.  I am still having a little problem getting some of  the VB.NET code to work after porting over.  The functionality works but the “Right Click“ support in designer is still broken...

 

[HumanCompiler]

www.WindowsForms.NET has made me the new Code Hero for my ControlArray that I've mentioned before.

Thanks WindowsForms Team!


Recent Posts

Tag Cloud

2 Comments

  • Cool, glad you like it. If you need any help porting stuff, let me know. I like the idea of having a common modified event...very cool idea.



    As for doing more "specific" events and properties, you might want to instead inherit from ControlArray and build new ones for specific controls (event strongly type it). There are methods in there to set a property or call a method on any control, so you shouldn't have to do that work over again or anything.



    Have fun! :)

  • p.s. I will try to get my bits posted after I get a chance to work on it this weekend. I am still having a little problem getting some of the VB.NET code to work after porting over. The functionality works but the “Right Click“ support in designer is still broken...

Comments have been disabled for this content.