Hello:
I have many forms that have the same code that I would like to put in one place and access it from all the forms. An example of the code is listed below:
public void textBox_Enter(object sender, EventArgs e)
{
((TextBox)sender).BackColor = Color.Ivory;
toolStripStatusLabelHint.Text = "Hint: " + ((TextBox)sender).Name;
//... and more code here
}
How can I put this in one place and then have a one line code to have it include the statements?
Also I have this code that I would need to put in one place.
InitializeComponent();
//------------------------------------------------------------
string d = "";
string e = "";
Control c = GetNextControl(null, true);
while (c != null)
{
if (c.GetType().Name == "TextBox")
{
c.Enter += new EventHandler(textBox_Enter);
c.Leave += new EventHandler(textBox_Leave);
}
c = GetNextControl(c, true);
}
//------------------------------------------------------------
.....
Loading
Sam HobbsPosted Mar 11, 2010, 1:58 AM
GustavoPosted Mar 11, 2010, 9:15 AM
Sam:
I guess for now I will go thr Inherited form way.
Hirendra:
I tried your way and I can use this method for some other things,. But it did not help for this issue because I can not put the routine that changes the toolStripStatusHint.Text. Thanks anyways.
Hirendra SisodiyaPosted Mar 10, 2010, 11:40 PM
public static void TExtbox_EnterEvent(object txtbox_Obj)
{
System.Windows.Forms.TextBox txtbox = (System.Windows.Forms.TextBox)txtbox_Obj;
txtbox.BackColor = System.Drawing.Color.Ivory;
//toolStripStatusLabelHint.Text = "Hint: " + txtbox.Name;
//... and more code here
}
and access this on any form like :
private void textBox1_TextChanged(object sender, EventArgs e)
{
Class1.Textbox_EnterEvent(sender);
}
thanks