有一变量 dim A as boolean,我想用它标记Text1中的文本是否被修改过。是在change事件中处理好呢?还是keydown、keyup、validate?还是其他什么事件过程中处理比较合适? 因为我要在用户手工修改此文本框中的内容时,包括paste等操作,才标记为已修改,A=True。如果是由代码中修改text1的值,则忽略,即A=false。 应该怎么处理?请给出示例代码。谢谢。
有一变量 dim A as boolean,我想用它标记Text1中的文本是否被修改过。是在change事件中处理好呢?还是keydown、keyup、validate?还是其他什么事件过程中处理比较合适? 因为我要在用户手工修改此文本框中的内容时,包括paste等操作,才标记为已修改,A=True。如果是由代码中修改text1的值,则忽略,即A=false。 应该怎么处理?请给出示例代码。谢谢。
MsgBox "Text1_Change"
End Sub
Private Sub Command1_Click()
If Text1.DataChanged = True Then
MsgBox "Text1数据已经修改"
End If
End Sub
if B then A=True '由引判斷是不是由代號改變還是用戶按了鍵改變
End SubPrivate Sub Text1_KeyDown(....)
B=True
End Sub
private sub text1_change()
a=true'内容改变时,记录为true
end sub再定义一个专门用来从代码中改变文本内容的过程
private sub ChangeTextBoxByCode(byval NewText as string,txtbox as TextBox )
txtbox.text=newtext
a=false'把标志变量强制为false
end sub要从代码中改变文本框内容只要这样调用就可以了:ChangeTextBoxByCode "Hi!" , text1
也会触发Text1_Change事件。
Dim strTmp As StringPrivate Sub Form_Load()
strTmp = Text1.Text
End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If strTmp <> Text1.Text Then
a = True
End If
End SubPrivate Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If strTmp <> Text1.Text Then
a = True
End If
End Sub
......if text1.text<>textA then
msgbox "文本内容改变"
end if
Private Sub Command1_Click()
Dim str As String
str = "改动的字符"
blnModify = IIf(Text1.Text <> str, True, False)
Text1.Text = str
End SubPrivate Sub Text1_Change()
If blnModify Then
MsgBox "代码改动"
Else
MsgBox "人工改动"
End If
blnModify = False
End Sub