Finding what caused TextBox.Text to change?

  • Thread starter Thread starter Matt B
  • Start date Start date
M

Matt B

This seems like it has probably been covered many times before, but
I'm having a hard time finding any discussion about it (probably just
searching the wrong terms).

Is there a way to capture whether the Text of a TextBox has been
changed by code or the user. I don't care if the Text is changed by
code, only if the user changes it. I actually figured out a solution
using a flag for the TextBox

something like:

OnKeyPress()
{
SetBoolFlag(true);
}

OnTextChanged()
{
if (BoolFlag == true)
DoSomething();
}

But, besides not liking how that works, it doesn't handle when a user
may "cut" text out of the TextBox using the mouse.

So, I'm back to my original problem. How can I find out (maybe at the
TextChanged event?) what caused the Text to change?

Any help is greatly appreciated,
Matt
 
But, besides not liking how that works, it doesn't handle when a user
may "cut" text out of the TextBox using the mouse.

So, I'm back to my original problem. How can I find out (maybe at the
TextChanged event?) what caused the Text to change?

AFAIK, you can't find out what caused the text to change. You have to set
flags like you are doing.

Michael
 
Hi,


Matt B said:
This seems like it has probably been covered many times before, but
I'm having a hard time finding any discussion about it (probably just
searching the wrong terms).

Is there a way to capture whether the Text of a TextBox has been
changed by code or the user. I don't care if the Text is changed by
code, only if the user changes it. I actually figured out a solution
using a flag for the TextBox

something like:

OnKeyPress()
{
SetBoolFlag(true);
}

OnTextChanged()
{
if (BoolFlag == true)
DoSomething();
}

But, besides not liking how that works, it doesn't handle when a user
may "cut" text out of the TextBox using the mouse.

So, I'm back to my original problem. How can I find out (maybe at the
TextChanged event?) what caused the Text to change?

AFAIK there is no way of doing it, after all the event is TextChanged , it
does not takes into account how the change occured.

I think you could accomplish this if you extend the TextBox and use a
solution similar to the above but taking all possible events sources.
 
Back
Top