Disabling Enter Key Typed in RTB based on some condition

  • Thread starter Thread starter sravan_reddy001
  • Start date 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
 
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;
}
 
Back
Top