Hello:
I have the following code in mty programs. I would like to put it in a class or something and just call it. So I can get rid of the redunda nt code in all my forms. Any suggestions?
I have tried to put it in a class, but it gives me an error on the 'GetNextControl'.
public FormICEPack()
{
InitializeComponent();
//
Control TheControl = GetNextControl(null, true);
while (TheControl != null)
{
if (TheControl.GetType().Name == "TextBox")
{
TheControl.Enter += new EventHandler(Object_Enter);
TheControl.Leave += new EventHandler(Object_Leave);
TheControl.Click += new EventHandler(Object_Click);
TheControl.MouseHover += new EventHandler(textBox_MouseHover);
TheControl.MouseLeave += new EventHandler(textBox_MouseLeave);
}
TheControl = GetNextControl(TheControl, true);
}
}
Loading
Sam HobbsPosted Mar 31, 2010, 7:21 PM
Probably the only reason that GetNextControl does not work in another class is that you need to pass the Form. When you learn the fundamentals of C#, it will be as clear as air that that is needed and and how to do it.
GustavoPosted Mar 31, 2010, 8:56 PM
I have written so many routines in the past few weeks. Now its time to clean them up and put them in their own place, so I can reduce code in the forms.
If I remember correctly: My Login program was like 800 lines and now its down to 200 lines. I recently wrote routines to do validation to about 10 different types and it works cool. The validation routines are long and I hate to repeat the code in every form.
Sam HobbsPosted Mar 31, 2010, 8:48 PM
GustavoPosted Mar 31, 2010, 8:33 PM
Thanks... you used the key word that I was looking for to find my solution. "UserControl"... Thanks