I have a (custom) MyTextbox
. MyTextbox in on (custom) MyPanel
, and the panel is on the MyForm
.
When the user edits text in MyTextbox and press, say "DEL" the MyForm recieves the _KeyDown
event...
But on the form I programmed an other action to do when pressing on "Delete", so it performs the Form action along with the textbox selection deleting...
How to stop the event propagation from the textbox to the form, or identify the textbox as the sender of the event?
PS.
I can't turn KeyPreview to "False" for multiple reasons, I need to find another solution.
PPS.
Imagine the MS Word editor in whitch you have a editable "rectangle" ... If you edit the text in the rectangle (in edition mode the rectangle is selected), your "Del" should delete chars in the rectangle, if not, it should delete the rectangle itself... (if the rectangle is selected).
In my case, I am in the edition mode in rectangle I selected some text, but when I press DEL instead of deleting the text, is removes the rectangle itself....
Make sure the form's KeyPreview property is set to False, which is usually the default for a form.
A possible work-around if you have KeyPreview=true
is to check the active control and filter the Form's handling of the key events:
protected override void OnKeyDown(KeyEventArgs e) {
if (ActiveControl.GetType() != typeof(TextBox)) {
base.OnKeyDown(e);
}
}