Walk through self-made controls on a form?

  • Thread starter Thread starter dr.p.dietz
  • Start date Start date
D

dr.p.dietz

Hello,
i've created my own TextBox based on standard .net-Textbox
as described by MS for my own properties of the textbox
and use it in another project.

I add the tx=new MyOwnControls.OwnTextbox by code on the
form, this works with me.controls.add(tx).

But when i try to access the tx in me.controls, i receive
an error: 'System.InvalidCastException'

for each tx in me.controls <---
...
next

How can i run through myOwnControls.OwnTextboxes in Form1?
Thanks!
Peter
 
Hi!

The form contains more controls than the ones you have added. When you try
to go through the controls you must first check if the control is of
MyOwnControls.OwnTextbox type.

foreach (Control ctrl in this.Controls)
{
if (ctrl is (MyOwnControls.OwnTextbox))
{
MyOwnControls.OwnTextBox tb = (MyOwnControls.OwnTextBox)ctrl;
//Do what you want to do with the textbox here
}
}

I hope this helps

//Mikael
 
I've tried several possibilities and found also your
solution.

..net seems to be very logical ;-)
Peter
 
Back
Top