VB中判断光标位置的问题
请各位帮我看看下面的代码,这是VB二级考试题库中1道题给的答案,里面vbcopy,cbcut....都是菜单项的名称,题目的大致意思是通过判断光标在TEXT1,TEXT2...
请各位帮我看看下面的代码,这是VB二级考试题库中1道题给的答案,里面vbcopy,cbcut....都是菜单项的名称,题目的大致意思是通过判断光标在TEXT1,TEXT2,TEXT3哪个上,能触发对应的事件
Dim which as integer
Private Sub vbCopy_Click()
If which = 1 Then
Text3.Text = Text1.Text '主要是这点不懂,为什么当光标在TEXT1时,which的值就是1呢,通过什么确定了这个变量which的值
ElseIf which = 2 Then
Text3.Text = Text2.Text
End If
End Sub
Private Sub vbCut_Click()
If which = 1 Then
Text3.Text = Text1.Text
Text1.Text = ""
ElseIf which = 2 Then
Text3.Text = Text2.Text
Text2.Text = ""
End If
End Sub
Private Sub vbEdit_Click()
If which = 1 Then
If Text1.Text = "" Then
vbCut.Enabled = False
vbCopy.Enabled = False
Else
vbCut.Enabled = True
vbCopy.Enabled = True
End If
ElseIf which = 1 Then
If Text2.Text = "" Then
vbCut.Enabled = False
vbCopy.Enabled = False
Else
vbCut.Enabled = True
vbCopy.Enabled = True
End If
End If
If Text3.Text = "" Then
vbPaste.Enabled = False
Else
vbPaste.Enabled = True
End If
End Sub 展开
Dim which as integer
Private Sub vbCopy_Click()
If which = 1 Then
Text3.Text = Text1.Text '主要是这点不懂,为什么当光标在TEXT1时,which的值就是1呢,通过什么确定了这个变量which的值
ElseIf which = 2 Then
Text3.Text = Text2.Text
End If
End Sub
Private Sub vbCut_Click()
If which = 1 Then
Text3.Text = Text1.Text
Text1.Text = ""
ElseIf which = 2 Then
Text3.Text = Text2.Text
Text2.Text = ""
End If
End Sub
Private Sub vbEdit_Click()
If which = 1 Then
If Text1.Text = "" Then
vbCut.Enabled = False
vbCopy.Enabled = False
Else
vbCut.Enabled = True
vbCopy.Enabled = True
End If
ElseIf which = 1 Then
If Text2.Text = "" Then
vbCut.Enabled = False
vbCopy.Enabled = False
Else
vbCut.Enabled = True
vbCopy.Enabled = True
End If
End If
If Text3.Text = "" Then
vbPaste.Enabled = False
Else
vbPaste.Enabled = True
End If
End Sub 展开
2个回答
展开全部
你这代码不完整吧?应该还有三个事件过程:
Private Sub Text1_GotFocus()
which = 1 '当Text1获得焦点时,就把which的值设为1。下面类推。
End Sub
Private Sub Text2_GotFocus()
which = 2
End Sub
Private Sub Text3_GotFocus()
which = 3
End Sub
或者是:
Private Sub Text1_Click()
which = 1 '当用鼠标点击Text1时,就把which的值设为1。下面类推。
End Sub
Private Sub Text2_Click()
which = 2
End Sub
Private Sub Text3_Click()
which = 3
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询