Table of contents
TOC
折叠目录
展开目录

禁用的 EnterFieldBehavior、SelLength、SelStart、SelText 属性示例Enabled, EnterFieldBehavior, SelLength, SelStart, SelText Properties Example

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

以下示例将跟踪选择相关属性 ( SelLengthSelStartSelText ),当用户将插入点移动和扩展所选内容使用键盘更改。此示例还使用了已启用EnterFieldBehavior属性。The following example tracks the selection-related properties ( SelLength, SelStart, and SelText ) that change as the user moves the insertion point and extends the selection using the keyboard. This example also uses the Enabled and EnterFieldBehavior properties.

若要使用此示例,请复制比示例代码到窗体的声明部分。确保该窗体包含:To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • 一个大文本框名为 TextBox1。One large TextBox named TextBox1.

  • 在列中的三个文本框控件命名 TextBox2 通过 TextBox4。Three TextBox controls in a column named TextBox2 through TextBox4.

Private Sub TextBox1_KeyUp(ByVal KeyCode As _ 
 MSForms.ReturnInteger, ByVal Shift As Integer) 
 TextBox2.Text = TextBox1.SelStart 
 TextBox3.Text = TextBox1.SelLength 
 TextBox4.Text = TextBox1.SelText 
End Sub
Private Sub UserForm_Initialize() 
 TextBox1.MultiLine = True 
 TextBox1.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorRecallSelection 

 TextBox1.Text = "Type your text here. Use " _ 
 &; "CTRL+ENTER to start a new line." 
End Sub
© 2018 Microsoft