Disabling Enter Key Typed in RTB based on some condition

  • Thread starter sravan_reddy001
  • Start date
S

sravan_reddy001

Hello,

My application is providing Intellisense thing.

I've a problem in my application.


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 = "";
//since the event is cancelled(i.e., SPACE or
ENTER is cancelled),
//the selectionstart will be the current position
wordindex = richTextBox1.SelectionStart;
e.Handled = true;
}
// If the character is typed
else
{
wordindex = richTextBox1.SelectionStart + 1;
}
buffer = "";
listBox1.Visible = false;
//e.Handled = true;
}


in the above code, I'm able to cancel the SPACE from being added to
RichTextBox(RTB),
but I've problem in avoiding ENTER typed in RTB.

Help Please,
Thanks in advance
 
J

Josip Medved

in the above code, I'm able to cancel the SPACE from being added to
RichTextBox(RTB),
but I've problem in avoiding ENTER typed in RTB.

Put code in KeyDown:

if (e.KeyData == Keys.Enter) {
e.Handled = true;
}
 

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

Similar Threads


Top