Attribute VB_Name = "Module1"
Public gFindDirection As Integer
Public gFindString   As String
Public gCurPos As Integer
Public gFirstTime As Integer
Public no As Integer
Public Sub CutProc()
     Clipboard.SetText frmMDI.ActiveForm.ActiveControl.SelText
     frmMDI.ActiveForm.ActiveControl.SelText = ""
End Sub
Public Sub PasteProc()
     frmMDI.ActiveForm.ActiveControl.SelText = Clipboard.GetText
      
End Sub

Public Sub CopyProc()
      Clipboard.SetText frmMDI.ActiveForm.ActiveControl.SelText
End Sub

Public Sub FileNew()
 Dim newdoc As New frmMDIChild
 no = no + 1
 newdoc.Caption = "no" & no
 newdoc.Show
End Sub

Public Sub FileSave()
   'If Left(frmMDI.ActiveForm.Caption, 2) = "No" Then
     frmMDI.ActiveForm.CommonDialog1.Action = 2
     frmMDI.ActiveForm.ActiveControl.SaveFile frmMDI.ActiveForm.CommonDialog1.FileName, rtfRTF
   'End If
End Sub
Public Sub FileOpen()
   If frmMDI.ActiveForm Is Nothing Then FileNew
   With frmMDI.ActiveForm
    .CommonDialog1.Filter = "RTF文件(*.rtf)|*.rtf|TXT文件(*.txt)|*.txt"
    .CommonDialog1.Action = 1
    If .CommonDialog1.FilterIndex = 1 Then
      .RichTextBox1.LoadFile .CommonDialog1.FileName
    Else
      .RichTextBox1.LoadFile .CommonDialog1.FileName, 1
    End If
    .Caption = .CommonDialog1.FileName
   End With
End Sub

Public Sub FileClose()
   Unload Me
End Sub

Public Sub insertpicture()
     
     frmMDI.ActiveForm.CommonDialog1.Filter = "*.bmp|*.bmp|*.ico|*.ico|*.wmf|*.wmf"
     frmMDI.ActiveForm.CommonDialog1.Action = 1
      frmMDI.ActiveForm.RichTextBox1.OLEObjects.Add
End Sub
'Sub FindIt()
'    Dim intStart As Integer
'    Dim intPos As Integer
'    Dim strFindString As String
'    Dim strSourceString As String
'    Dim strMsg As String
'    Dim intResponse As Integer
'    Dim intOffset As Integer
'
'    ' 根据当前光标位置设置偏移量变量。
'   intStart = frmMDI.ActiveForm.ActiveControl.SelStart
'    ' 为起始位置读全局变量。
''   If gFirstTime Then intOffset = 0
''    ' 给搜索起始位置赋值。
''    intStart = frmMDI.ActiveForm.ActiveControl.SelStart + intOffset
''
'    ' 如果不匹配大小写，将字符串转换成大写。
'    If frmFind.chkCase.Value Then
'        strFindString = gFindString
'        strSourceString = frmMDI.ActiveForm.ActiveControl.Text
'    Else
'        strFindString = UCase(gFindString)
'        strSourceString = UCase(frmMDI.ActiveForm.ActiveControl.Text)
'    End If
'
'    ' 搜索字符串。
'    If gFindDirection = 1 Then
'        intPos = InStr(intStart + 1, strSourceString, strFindString)
'    Else
'        For intPos = intStart - 1 To 0 Step -1
'            If intPos = 0 Then Exit For
'            If Mid(strSourceString, intPos, Len(strFindString)) = strFindString Then Exit For
'        Next
'    End If
'
'    ' 如果找到了字符串...
'    If intPos Then
'        frmMDI.ActiveForm.ActiveControl.SelStart = intPos - 1
'        frmMDI.ActiveForm.ActiveControl.SelLength = Len(strFindString)
'    Else
'        strMsg = "找不到 " & Chr(34) & gFindString & Chr(34)
'        intResponse = MsgBox(strMsg, 0, App.Title)
'    End If
'    ' 重新设置全局变量
'    gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart
'    gFirstTime = False
'End Sub
Sub FindIt()
    Dim intStart As Integer
    Dim intPos As Integer
    Dim strFindString As String
    Dim strSourceString As String
    Dim strMsg As String
    Dim intResponse As Integer
    Dim intOffset As Integer
    
    ' 根据当前光标位置设置偏移量变量。
    If (gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart) Then
        intOffset = 1
    Else
        intOffset = 0
    End If

    ' 为起始位置读全局变量。
    If gFirstTime Then intOffset = 0
    ' 给搜索起始位置赋值。
    intStart = frmMDI.ActiveForm.ActiveControl.SelStart + intOffset
        
    ' 如果不匹配大小写，将字符串转换成大写。
    If gFindCase Then
        strFindString = gFindString
        strSourceString = frmMDI.ActiveForm.ActiveControl.Text
    Else
        strFindString = UCase(gFindString)
        strSourceString = UCase(frmMDI.ActiveForm.ActiveControl.Text)
    End If
            
    ' 搜索字符串。
    If gFindDirection = 1 Then
        intPos = InStr(intStart + 1, strSourceString, strFindString)
    Else
        For intPos = intStart - 1 To 0 Step -1
            If intPos = 0 Then Exit For
            If Mid(strSourceString, intPos, Len(strFindString)) = strFindString Then Exit For
        Next
    End If

    ' 如果找到了字符串...
    If intPos Then
        frmMDI.ActiveForm.ActiveControl.SelStart = intPos - 1
        frmMDI.ActiveForm.ActiveControl.SelLength = Len(strFindString)
    Else
        strMsg = "找不到 " & Chr(34) & gFindString & Chr(34)
        intResponse = MsgBox(strMsg, 0, App.Title)
    End If
    
    ' 重新设置全局变量
    gCurPos = frmMDI.ActiveForm.ActiveControl.SelStart
    gFirstTime = False
End Sub



