记事本代码
Dim Fname$, st$, sfind$
Private Sub BackColor_Click()
CommonDialog1.ShowColor
RichTextBox1.BackColor = CommonDialog1.Color
End Sub
Private Sub Close_Click()
Dim i%
i = MsgBox(Form1.Caption & ".text文件已经改变,想保存文件吗,", 3 + vbExclamation, "
记事本")
If i = 6 Then
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
Write #1, RichTextBox1.Text
Close #1
Else
Open Fname For Output As #1
Write #1, RichTextBox1.Text
Close #1
End If
If i = 7 Then
Form1.Caption = "未定标题-记事本"
RichTextBox1.Text = ""
Fname = ""
End If
End Sub
Private Sub Copy_Click()
st = RichTextBox1.SelText End Sub
Private Sub Cut_Click()
st = RichTextBox1.SelText
RichTextBox1.SelText = "" End Sub
Private Sub Delete_Click()
RichTextBox1.SelText = "" End Sub
Private Sub Exit_Click()
Dim i%
i = MsgBox(Form1.Caption & ".text文件已经改变,想保存文件吗,", 3 + vbExclamation, "记
事本")
If i = 6 Then
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
Write #1, RichTextBox1.Text
Close #1
Else
Open Fname For Output As #1
Write #1, RichTextBox1.Text
Close #1
End If
If i = 7 Then
End
End If
End Sub
Private Sub form_load()
If Len(RichTextBox1.SelText) = 0 Then
NextFind.Enabled = False
End If
End Sub
Private Sub Find_Click()
sfind = InputBox("请输入要查找的字符:", "查找")
RichTextBox1.Find sfind
If Len(RichTextBox1.SelText) <> 0 Then
NextFind.Enabled = True
End If
End Sub
Private Sub Font_Click()
CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
CommonDialog1.ShowFont
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
RichTextBox1.Font.Strikethrough = CommonDialog1.FontStrikethru
RichTextBox1.SelColor = CommonDialog1.Color End Sub
Private Sub Form_Resize()
RichTextBox1.Height = Form1.Height - 400
RichTextBox1.Width = Form1.Width - 400 End Sub
Private Sub New_Click()
RichTextBox1 = ""
Form1.Caption = "未定标题-记事本"
Fname = ""
End Sub
Private Sub NextFind_Click()
RichTextBox1.SelStart = RichTextBox1.SelStart + RichTextBox1.SelLength
RichTextBox1.Find sfind, , Len(RichTextBox1)
If Len(RichTextBox1.SelText) = 0 Then
MsgBox "以达到文档的结尾部分,搜索结束", 64, "查找完毕"
NextFind.Enabled = True
End If
End Sub
Private Sub Open_Click()
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Fname = CommonDialog1.FileName
If FileLen(Fname) > 65536 Then
MsgBox "该文件太大,不能显示", 0, "记事本"
Else
RichTextBox1.Text = ""
Do While Not EOF(1)
InputDate = Input(1, #1)
RichTextBox1.Text = RichTextBox1.Text + InputDate
Loop
Form1.Caption = Fname & "-记事本"
End If
Close #1
End Sub
Private Sub All_Click()
RichTextBox1.Find RichTextBox1.Text End Sub
Private Sub Paste_Click()
RichTextBox1.SelText = st
End Sub
Private Sub Save_Click()
If Fname = "" Then
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
Write #1, RichTextBox1.Text
Close #1
Else
Open Fname For Output As #1 Write #1, Text1
Close #1
End If
End Sub
Private Sub SaveAs_Click() CommonDialog1.ShowSave Open CommonDialog1.FileName For Output As #1
Write #1, RichTextBox1 Close #1
End Sub
Private Sub Time_Click() RichTextBox1.SelText = Now End Sub