Private Sub Form_Click ()
If TypeOf Screen.ActiveControl Is TextBox Then
Label1.Caption = Screen.ActiveControl.Text
Else
Label1.Caption = "Button: " + Screen.ActiveControl.Caption
End If
End Sub
Private Sub MDIForm_Load ()
Dim I ' 声明变量。
Command1(0).Move 0, 0, 700, 300 '在工具栏上为按钮定位。
For I = 1 To 3 '创建别的按钮。
Load Command1(I) '创建按钮。
Command1(I).Move I * 700, 0, 700, 300 '放置并调整按钮大小。
Command1(I).Visible = True '显示按钮。
Next I
Command1(0).Caption = "Cut" '设置按钮标题。
Command1(1).Caption = "Copy"
Command1(2).Caption = "Paste"
Command1(3).Caption = "Del"
End Sub
Private Sub Command1_Click (Index As Integer)
'ActiveForm 是指 MDI 窗体中的活动窗体。
If TypeOf ActiveForm.ActiveControl Is TextBox Then
Select Case Index
Case 0 '剪切。
'复制选中的文本到剪贴板上。
Clipboard.SetText ActiveForm.ActiveControl.SelText
'删除选中的文本。
ActiveForm.ActiveControl.SelText = ""
Case 1 '复制。
' 复制选中的文本到剪贴板上。
Clipboard.SetText ActiveForm.ActiveControl.SelText
Case 2 '粘贴。
'把剪贴板上的文本放到文本框中。
ActiveForm.ActiveControl.SelText = Clipboard.GetText()
Case 3 '删除。
'删除选中的文本。
ActiveForm.ActiveControl.SelText = ""
End Select
End If
End Sub