Cancel the Generated Event. KeyPress & KeyDown

S

sravan_reddy001

I'm developing a Text Editor for HTML. (auto fill code OR Intellisense
is included)

I've a problem in my project. When I press the ENTER key(in
the RichTextBox), the selected value in the listbox is added to the
RichTextBox Control. But the enter is also added to the text. How can
I cancel the Event so that the Enter is not typed in.

else if (e.KeyChar.Equals((char)Keys.Enter) || e.KeyChar.Equals((char)
Keys.Space))
{
//add the item only if it is visible and there are
items in it
if (listBox1.Visible == true && listBox1.Items.Count !
= 0)
{
richTextBox1.Select(wordindex, buffer.Length);
richTextBox1.SelectedText =
listBox1.SelectedItem.ToString();
}
buffer = "";
listBox1.Visible = false;
wordindex = richTextBox1.SelectionStart + 1;
e.Handled =
false;
//-> the problem is here. This code is in KeyPress Event of
RichTextBox. i tried Handled Property. It didn't work.
//-> I also used e.Handled and e.SuppressKeyPress = false; in KeyDown
Event.
}

How can I stop Enter and Space from adding to RichTextBox Control.

Thanks in advance
 
P

Peter Morris

e.Handled = false;
//-> the problem is here. This code is in KeyPress Event of
RichTextBox. i tried Handled Property. It didn't work.
//-> I also used e.Handled and e.SuppressKeyPress = false; in KeyDown
Event.

You need to set Handled = true, not false.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top