Вопрос

I have a textbox in Form and i want to detect when the text has changed but the code I have found is giving me no joy.

I am probably missing something in the proporties or something you have to define before.

Here is my code:

private void tbxparkingTimesS1_TextChanged(Object sender, EventArgs e)
{
     MessageBox.Show("You are in the ToolStripItem.TextChanged event.");
}

Thanks for any help with this trivial problem.

Это было полезно?

Решение

To wire the TextChanged event to a particular method inside your code do the following

  • Click on the TextBox inside your form
  • Open the properties windows (press F4 or menu View -> Property Window )
  • Select the event page (lightning icon)
  • Double click on the TextChanged property line
  • Insert your code inside the template build for you by Visual Studio

Другие советы

Have you assigned the event handler to the textbox?

Normally this will be done "behind the scenes" by Visual Studio - with the result being an additional line of code in your .designer file.

Something like:

this.tbxparkingTimesS1.TextChanged += new System.EventHandler(tbxparkingTimesS1_TextChanged);

(It['s been a while since I've done webforms - so that might be slightly off)

Double Click on Text box it will generate text change event for you.

    private void tbxparkingTimesS1_TextChanged(object sender, EventArgs e)
    {
        // implement your code here. 
    }

When you double click VS will create event handler in your designer.cs file as bellow

 this.tbxparkingTimesS1.TextChanged += new System.EventHandler(this.tbxparkingTimesS1_TextChanged);

You can do the same by using property window events or create event on code behind.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top