问题
I set the property Multiline=true;
.
I do not want to allow the Enter Key to make a new line.
How can I solve this issue?
回答1:
That could be as simple as listening to TextChanged
event and then executing the following line inside it:
txtYourTextBox.Text = txtYourTextBox.Text.Replace(Environment.NewLine, "");
This solution involves some screen flicker though. A better way is to prevent it entirely by listening to KeyDown
event:
private void txtYourTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
e.SuppressKeyPress=true;
}
来源:https://stackoverflow.com/questions/25700992/do-not-allow-enter-key-to-make-a-new-line-in-multiline-textbox-c-sharp