Dim sfind As String   '定义一个字符串变量
Dim oFile As String   '定义一个字符串变量
Dim sFile As String
Dim i As Integer
Private Sub Form_Load()
    Form_Resize
'调用Private Sub Form_Resize()过程
    记事本.RichTextBox1.Text = ""
'清空文本框中的内容
End SubPrivate Sub Form_Resize()
RichTextBox1.Move 5, 410, Me.ScaleWidth - 5, Me.ScaleHeight - 370
'改变控件尺寸
End SubPrivate Sub mnuAbout_Click()
Dim myexit As Integer
myexit = MsgBox("这是韩柏的个人记事本", vbOKOnly, "关闭")
'给出程序编写者的信息
End SubPrivate Sub mnuClose_Click()
记事本.RichTextBox1.Text = ""
'清空文本框
End SubPrivate Sub mnuCopy_Click()
Clipboard.SetText 记事本.RichTextBox1.SelText
'复制选定文本到剪贴板
End SubPrivate Sub mnuCut_Click()
Clipboard.SetText 记事本.RichTextBox1.SelText
'复制选定文本到剪贴板
记事本.RichTextBox1.SelText = ""
'删除选定文本
End SubPrivate Sub mnuExit_Click()
End
'结束程序的运行
End Sub
Private Sub mnuFindNext_Click()
RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength + 1
RichTextBox1.Find sfind, , Len(RichTextBox1)
End SubPrivate Sub mnuFindOn_Click()
sfind = InputBox("请输入你要查找的信息?", , sfind)
RichTextBox1.Find sfind
End SubPrivate Sub mnuFont_Click()
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
RichTextBox1.Font.Strikethrough = CommonDialog1.FontStrikethru
End SubPrivate Sub mnuNEW_Click()
记事本.RichTextBox1.Text = ""
'清空文本框
End SubPrivate Sub mnuOpen_Click()    With CommonDialog1
        .DialogTitle = "打开"
'设置对话框标题
        .Filter = "Text Files(*.txt)|*.txt|Rtf Files(*.rtf)|*.rtf|All Files (*.*)|*.*"
'设置过滤器
        .ShowOpen
'打开对话框
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        oFile = .FileName
End With
记事本.RichTextBox1.LoadFile oFile
'读取文件信息
记事本.Caption = oFile
'设置窗口标题
End SubPrivate Sub mnuPaste_Click()
记事本.RichTextBox1.SelText = Clipboard.GetText()
'将文本从剪贴板粘贴到活动控件
End Sub
Private Sub mnuSave_Click()
  With CommonDialog1
       .DialogTitle = "保存"
'设置对话框标题
       .Filter = "Text Files(*.txt)|*.txt|Rtf Files(*.rtf)|*.rtf|All Files (*.*)|*.*"
'设置过滤器
       .ShowSave
'显示对话框
        If Len(.FileName) = 0 Then
            Exit Sub
        End If
        sFile = .FileName
  End With
记事本.RichTextBox1.SaveFile sFile
'存储文件
End SubPrivate Sub mnuSelsctAll_Click()
RichTextBox1.SelStart = 0
'设置初始值
RichTextBox1.SelLength = Len(RichTextBox1.Text)
'定义文本全选
End SubPrivate Sub Timer1_Timer()
Select Case i
  Case 1
    ret = SendMessageBynum(RichTextBox1.hwnd, EM_LINESCROLL, 0, 1)
  Case 2
    ret = SendMessageBynum(RichTextBox1.hwnd, EM_LINESCROLL, 0, 0)
End Select
End SubPrivate Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
  Case "打开"
        Call mnuOpen_Click
        
  Case "保存"
        Call mnuSave_Click
  
  Case "剪切"
        Call mnuCut_Click
        
  Case "拷贝"
        Call mnuCopy_Click
        
  Case "粘贴"
        Call mnuPaste_Click
  
  Case "字体"
        Call mnuFont_Click
  Case "自动上卷"
          i = 1
  Case "停止"
          i = 2
End Select
End Sub
Public Const EM_LINESCROLL = &HB6
Public Declare Function SendMessageBynum Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

解决方案 »

  1.   

    将richtextbox放在picturebox中,将文本框设置成与文本等高(通过计算文本中所包含的换行符的个数),再在timer中设置它的top属性。
      

  2.   

    to limengchen(lmc):
       谢谢你提供的代码,我刚才对RichTextBox控件中的内容,用计时器控件触发消息,发现RichTextBox中的内容是按指定的行数滚动的,但很难看,不知道怎样实现平滑滚动,再次谢谢,等会儿给分......
      

  3.   

    我看过别人编好的程序,文字(TXT和DOC文档)平滑滚动能实现,只是我不会,所以才提问
      

  4.   

    ACTIVEX
    FX TOOLS
    我不喜欢PRG