Replacing a Paragraph with a Line Break on Enter Key

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.

[C#]
private void textControl1_KeyPress(object sender, KeyPressEventArgs e) 
{
    if(e.KeyChar.Equals('\r'))
    {
        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

<< Back