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
jack haPosted Sep 7, 2009, 6:34 AM
sriPosted Jul 20, 2009, 4:36 PM
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.
sriPosted Jul 20, 2009, 4:12 PM
// 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.
naura paxPosted Jul 20, 2009, 4:54 AM
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.