Dim S As Long
Private WithEvents B1 As CommandButton, WithEvents T1 As TextBox
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim KT, KB1, nTName, nB1Name As String
If Button = 2 Then '右击添加控件
S = S + 1
'添加一个文本框
nTName = "MyText" & S
Set KT = Controls.Add("vb.textbox", nTName)
'Controls(nTName).Visible = True '也可以:KT.Visible = True
Controls(nTName).Text = nTName
Controls(nTName).Move 0, (S - 1) * 900, 4600, 800
If S = 1 Then Set T1 = KT
'添加一个按钮
nB1Name = "按钮1" & S
Set KB1 = Controls.Add("vb.CommandButton", nB1Name)
Controls(nB1Name).Visible = True
Controls(nB1Name).Caption = nB1Name
Controls(nB1Name).Move 0, (S - 1) * 900, 4600, 800
If S = 1 Then Set B1 = KB1
End If
End SubPrivate Sub B1_Click()
'按钮的单击事件
T1.Visible = True
B1.Visible = False
End Sub
Private Sub T1_DblClick()
'文本框的双击事件
B1.Caption = T1.Text
T1.Visible = False
B1.Visible = True
B1.Caption = T1.Text
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = True
Dim nName As String
On Error Resume Next
nName = ActiveControl.Name
If T1.Name <> nName Then
Set T1 = ActiveControl
Else
End If
If B1.Name <> nName Then
Set B1 = ActiveControl
End If
End Sub
本程序的目的是:添加几个command和text控件后,单击command控件后,出现text,把输入text的内容后返回到相应的command caption属性,本人不才,求指教
Private WithEvents B1 As CommandButton, WithEvents T1 As TextBox
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim KT, KB1, nTName, nB1Name As String
If Button = 2 Then '右击添加控件
S = S + 1
'添加一个文本框
nTName = "MyText" & S
Set KT = Controls.Add("vb.textbox", nTName)
'Controls(nTName).Visible = True '也可以:KT.Visible = True
Controls(nTName).Text = nTName
Controls(nTName).Move 0, (S - 1) * 900, 4600, 800
If S = 1 Then Set T1 = KT
'添加一个按钮
nB1Name = "按钮1" & S
Set KB1 = Controls.Add("vb.CommandButton", nB1Name)
Controls(nB1Name).Visible = True
Controls(nB1Name).Caption = nB1Name
Controls(nB1Name).Move 0, (S - 1) * 900, 4600, 800
If S = 1 Then Set B1 = KB1
End If
End SubPrivate Sub B1_Click()
'按钮的单击事件
T1.Visible = True
B1.Visible = False
End Sub
Private Sub T1_DblClick()
'文本框的双击事件
B1.Caption = T1.Text
T1.Visible = False
B1.Visible = True
B1.Caption = T1.Text
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = True
Dim nName As String
On Error Resume Next
nName = ActiveControl.Name
If T1.Name <> nName Then
Set T1 = ActiveControl
Else
End If
If B1.Name <> nName Then
Set B1 = ActiveControl
End If
End Sub
本程序的目的是:添加几个command和text控件后,单击command控件后,出现text,把输入text的内容后返回到相应的command caption属性,本人不才,求指教
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货