Prevent RichTextBox from creating a new line when Enter is pressed
source link: https://www.codesd.com/item/prevent-richtextbox-from-creating-a-new-line-when-enter-is-pressed.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Prevent RichTextBox from creating a new line when Enter is pressed
This question already has an answer here:
- Custom RichTextBox Event Handle 1 answer
I want to run a method when the Enter key is pressed within a RichTextBox
so I made this code.
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
MessageBox.Show("Hello World");
}
But I don't want to make a new line when the Enter key is pressed. But I can't manage to make that work.
Use e.Handled = true;
this doesn't allow Enter Key to make a new line:
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("Hello World");
e.Handled = true;
}
Related Articles
How can I prevent sublime from inserting a new line when I stick?
Creating a new line when writing to a text file with javascript or jquery
Xpages - How to prevent users from creating a new document if there is already one
How to create a new line when the text overflows the line?
How to prevent others from creating a new instance of your class on the stack?
Select the following line when Enter is pressed when editing an NSTextField inside a NSTableView
How do you prevent others from creating a new instance of a class on the job?
SQL creates a new line when I execute an update command
Prevents Flexbox from displaying a new line
Prevent python from printing a new line
AngularJS - Creating a new line when using ng-repeat
How to prevent the enter key from creating a new row in a multi-line text box?
Unable to create a new line in my string
How to prevent users from creating repetitive identifiers?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK