편집

다음을 통해 공유


KeyDown event, TextBox control, CurLine, CurTargetX, CurX, Text properties example

The following example tracks the CurLine, CurTargetX, and CurX property settings in a multiline TextBox. These settings change in the KeyUp event as the user types into the Text property, moves the insertion point, and extends the selection by using the keyboard.

To use this example, follow these steps:

  1. Copy this sample code to the Declarations portion of a form.

  2. Add one large TextBox named TextBox1 to the form.

  3. Add three TextBox controls named TextBox2, TextBox3, and TextBox4 in a column.

Private Sub TextBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) 
 TextBox2.Text = TextBox1.CurLine 
 TextBox3.Text = TextBox1.CurX 
 TextBox4.Text = TextBox1.CurTargetX 
End Sub
Private Sub UserForm_Initialize() 
 TextBox1.MultiLine = True 
 
 TextBox1.Text = "Type your text here. User CTRL + ENTER to start a new line." 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.