求VB编程,题目为类似WINDOWS自带的记事本(TXT),求里面各种细节代码如何打
1个回答
展开全部
1个richtextbox,1个commondialog,菜单蓝设计好 打开文件代码: Private Sub Open_Click() If ChangeTxt Then If MsgBox("是否将更改保存到 " & FilePath & "?", vbYesNo + vbQuestion, "散喊脊记事本") = vbYes Then Save_Click End If End If CommonDialog1.Filter = "文本文档(*.txt)|*.txt|所有文件(*.*)|*.*" CommonDialog1.FilterIndex = 1 CommonDialog1.ShowOpen FilePath = CommonDialog1.FileName FileName = Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\")) OpenFile FilePath End Sub Private Sub OpenFile(FilePath As String) Dim F As Integer Dim FileStr As String On Error GoTo errhandler F = FreeFile FileStr = "" Open FilePath For Input As F Do While Not EOF(F) FileStr = FileStr + Input(1, #1) Loop Close F Form1.RichTextBox1.Text = FileStr Form1.Caption = FileName & " - 记事本" Exit Sub errhandler: MsgBox "打开文件出错,请重试", 48, "系统提示" Close F Exit Sub End Sub 保存那些类同 剪切复制代码如下: Private Sub Copy_Click() Clipboard.Clear Clipboard.SetText RichTextBox1.SelText End Sub Private Sub Cut_Click() Clipboard.Clear Clipboard.SetText RichTextBox1.SelText RichTextBox1.SelText = "" End Sub 主要功能就这样设计,个别功能需要自己完善,如果有兴趣还可渗庆以做出比windows自带的更强大的记事本,如添加字数统计等功能冲渗。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询