ybt
asked on
c# find out if selected(highlighted) text in textbox was replaced or removed
If user selected some text in textbox and then removed or replaced, how to determine than selected word was removed(replaced)
First, is it in winform or ASP?
Second: a) find out if something was selected, e.g.
b) e.g., compare text before and after...
Second: a) find out if something was selected, e.g.
private void textBox_KeyUp(object sender, KeyEventArgs e) {
if (textBox.SelectedText != "")
MessageBox.Show("Selected");
}
b) e.g., compare text before and after...
ASKER
This is winform and textBox.SelectedText != "" is not helpful, because user can unselect this text and there is nothing to check.
Compare with previous content - that's what Stefan and I told you already.
ASKER
Compare function gives only if strings equal or not
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi ybt,
How is TextChanged Event !!
Occurs when the Text property value changes. It occurs when the text is modified in a TextBox. With it make a program dependent on the value of a TextBox when the user types.
Regards,
Tapan Pattanaik
How is TextChanged Event !!
Occurs when the Text property value changes. It occurs when the text is modified in a TextBox. With it make a program dependent on the value of a TextBox when the user types.
Regards,
Tapan Pattanaik
If you select text and then unselect your event won't be fired. You don't even know if something was selected.
However, this event could be used in conjunction with KeyUp etc.
Also, we need to remember that some operations can be done by a mouse, so we need to code mouse events as well...
However, this event could be used in conjunction with KeyUp etc.
Also, we need to remember that some operations can be done by a mouse, so we need to code mouse events as well...
ASKER
Yes, algorithm is interesting and TextChanged Event I tried to use, not helpful.
Thank you
Thank you
The normal approach would be comparing the old value with the current value. Which means that you store old value in some variable and compare this variable with the current content.