Hi guys,
I have a class named AutoComplete and I have created a textbox form. I can access the text box by creating an instance of the form in AutoComplete class. But when I try to write event handler the code doesn't give error but it doesn't execute the event handler. When I included the event handler in Form class it worked fine.
TextboxForm form = new TextboxForm();
form.myTextBox.TextChanged += new EventHandler(myTextBox_TextChanged); // doesn't work
private void myTextBox_TextChanged(object sender, EventArgs e)
{
MessageBox.Show("Textbox working!!!");
}
I would appreciate if anyone can help me with this issue.
Thank you
Loading

naura paxRank #2,843 · 502 reputationPosted Jul 20, 2009, 12:54 AM EDT
Where do you actually start the textbox form instance?. Is it from a menu?
Or the form instance gets displayed only through this class?
I mean to say that you might have a separate means of displaying the form in your application, then in that case the form object instance created in your class AutoComplete is different from the one that is being displayed.
Instead you can write a piece of code within your Form application where you set the textchange event with the method in AutoComplete Class
yourForm.cs-
AutoComplete ac=new AutoComplete();
textBox1.TextChanged+=ac.YourMethodName
You can ask me if still not clear.
sri6 reputationPosted Jul 20, 2009, 12:12 PM EDT
// Form1.cs
AutoComplete autoComplete = new AutoComplete();
myTextBox.Click += new EventHandler(autoComplete.myTextBox_Click);
myButton.Click += new EventHandler(autoComplete.myButton_Click);
// AutoComplete.cs
public void myButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Button working!!!");
}
public void myTextBox_Click(object sender, EventArgs e)
{
MessageBox.Show("Textbox working!!!");
}
Thank you so much and I appreacite that.
sri6 reputationPosted Jul 20, 2009, 12:36 PM EDT
I could figure it out. I found out why it's creating the infinite loop. Thank you so much for the help. I appreciate that.
jack ha15 reputationPosted Sep 7, 2009, 2:34 AM EDT