I have the following code, meant to prevent user from writing new-lines in a memo text editor:
private void m_commentMemoEdit_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.HasFlag(Keys.Enter))
{
e.SuppressKeyPress = true;
}
}
It really does prevent Enter from being inserted, but strangely enough it prevents other keys from being inserted as well. So far we've discovered that the keys: 'O', 'M', '/' and '-' are also being "caught".
Update: The following code does what I need:
private void m_commentMemoEdit_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == (int)Keys.Return)
{
e.SuppressKeyPress = true;
}
}
But I still don't understand the former code does not work and this does.
I've looked at the System.Windows.Forms.Keys
enum but didn't find any clues (though I must say this is one weirdly constructed enum). Can anyone explain why is this happening?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…