Replacing a Paragraph with a Line Break on Enter Key

Technical Articles > How-To Guide

For some applications, it is necessary to replace the default keys with another key or action. The following code intercepts the Enter key and inserts a line break instead of a paragraph.

private void textControl1_KeyPress(object sender, KeyPressEventArgs e) 
        e.Handled = true;
        textControl1.Selection.Text = "\v";
[Visual Basic]
Private Sub textControl1_KeyPress(sender As Object, e As KeyPressEventArgs)
    If e.KeyChar.Equals(ControlChars.Cr) Then
        e.Handled = True
        textControl1.Selection.Text = vbVerticalTab
    End If
End Sub