有一变量 dim A as boolean,我想用它标记Text1中的文本是否被修改过。是在change事件中处理好呢?还是keydown、keyup、validate?还是其他什么事件过程中处理比较合适?    因为我要在用户手工修改此文本框中的内容时,包括paste等操作,才标记为已修改,A=True。如果是由代码中修改text1的值,则忽略,即A=false。    应该怎么处理?请给出示例代码。谢谢。

解决方案 »

  1.   

    在change事件中处理好Private Sub Text1_Change()
        MsgBox "Text1_Change"
    End Sub
      

  2.   

    但是在change事件中怎么判断不是由代码修改text1中的值而触发的呢?
      

  3.   

    '只要textbox的数据发生变化会改变DataChanged 的属性值为true
    Private Sub Command1_Click()
        If Text1.DataChanged = True Then
            MsgBox "Text1数据已经修改"
        End If
    End Sub
      

  4.   

    Dim A as Boolean,B as BooleanPrivate Sub Text1_Change()
        if B then A=True   '由引判斷是不是由代號改變還是用戶按了鍵改變
    End SubPrivate Sub Text1_KeyDown(....)
        B=True
    End Sub
      

  5.   

    这样行不行
    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
      

  6.   

    用change是不行的,当用代码改变修改text1的值时,
    也会触发Text1_Change事件。
      

  7.   

    用户手工修改此文本框中的内容时,包括paste等操作,才标记为已修改,A=True?建议使用鼠标和键盘事件结合起来使用如下:Dim a As Boolean
    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
      

  8.   

    tempA=text1.text
    ......if text1.text<>textA then
    msgbox "文本内容改变"
    end if
      

  9.   

    Dim blnModify As Boolean
    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