vb的简单记事本的代码

那为大哥能帮我做一个vb的记事本的代码
知道的加QQ83297077,有人会吗?提供流程图,代码,还有运行截图,提供QB奖励

'窗体代码

Option Explicit
Dim filename As String
Dim FileType As String
Dim FiType As String
Dim sFind As String
Dim result As String
Dim bWrap As Boolean
Dim ask As Boolean
Dim msgtext As String
Dim Flag As String

Private Sub Form_Load()
ask = False
RichText.Text = ""
filename = "无标题-记事本"
Form1.Caption = "无标题-记事本"
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
StatusBar1.Visible = False
StatusBar1.Panels(1).Text = Time
mnucopy.Enabled = False
mnucut.Enabled = False
mnufound.Enabled = False
mnufoundnext.Enabled = False
mnudel.Enabled = False
mnucancel.Enabled = False
mnuwordwrap.Checked = True
mnugoto.Enabled = False
If Clipboard.GetText <> "" Then
mnuplaster.Enabled = True
Else
mnuplaster.Enabled = False
End If
App.HelpFile = App.Path & "\notepad.chm"
End Sub

Private Sub Form_Resize()
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
End Sub

Private Sub Form_Unload(Cancel As Integer)
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") ' 35=32+3
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Cancel = True
If Flag = vbNo Then Unload Me
End If

End Sub

Private Sub mnuabout_Click()
MsgBox "记事本", vbOKOnly, "关于"
End Sub

Private Sub mnuall_Click()
RichText.SelStart = 0
RichText.SelLength = Len(RichText.Text)
End Sub

Private Sub mnucancel_Click()
MsgBox "请点击鼠标右键撤销!", vbOKOnly, "提示"
End Sub

Private Sub mnucopy_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
End Sub

Private Sub mnucut_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
RichText.SelText = ""

End Sub

Private Sub mnudel_Click()
RichText.SelText = ""
End Sub

Private Sub mnuedit_Click()
If RichText.SelText <> "" Then
mnuopen.Enabled = True
mnucut.Enabled = True
mnudel.Enabled = True
mnucopy.Enabled = True
End If
If Len(RichText.Text) <> 0 Then
mnufound.Enabled = True
mnufoundnext.Enabled = True
End If
If ask = True Then mnucancel.Enabled = True
End Sub

Private Sub mnuexit_Click()
Unload Me
End Sub

Private Sub mnufont_Click()
On Error Resume Next
CommonDialog1.flags = &H3 Or &H1 Or &H2 Or &H100
CommonDialog1.Action = 4
RichText.Font.Name = CommonDialog1.FontName
RichText.Font.Size = CommonDialog1.FontSize
RichText.Font.Bold = CommonDialog1.FontBold
RichText.Font.Italic = CommonDialog1.FontItalic
RichText.Font.Underline = CommonDialog1.FontUnderline
RichText.SelColor = CommonDialog1.Color

End Sub

Private Sub mnufound_Click()
sFind = InputBox("请输入要查找的字、词:", "查找内容", sFind)
RichText.Find sFind
End Sub

Private Sub mnufoundnext_Click()
RichText.SelStart = RichText.SelStart + RichText.SelLength + 1
RichText.Find sFind, , Len(RichText)

End Sub

Private Sub mnuhelptopic_Click()
SendKeys "{F1}"
End Sub

Private Sub mnunewfile_Click()
On Error Resume Next
Dim n As Integer
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
If Len(RichText.Text) <> 0 Then
If filename = "无标题-记事本" Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then
mnusaveas_Click
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then
RichText.Text = ""
Form1.Caption = "无标题-记事本"
filename = "无标题-记事本"
End If
End If
End If
End Sub

Private Sub mnuopen_Click()
msgtext = "文件" & filename & "的文字已经改变。" & Chr(10) & Chr(13) & "想保存文件吗?"
On Error Resume Next
If ask = True Then
Flag = MsgBox(msgtext, 35, "记事本") '给予提示
If Flag = vbYes Then mnusave_Click '选择了确定则保存之
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then GoTo L1
End If
ask = False

L1: CommonDialog1.Filter = "文本文档(*.txt)|*.txt|RTF文档(*.rtf)|*.rtf|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
RichText.Text = "" '清空文本框
filename = CommonDialog1.filename
RichText.LoadFile filename
result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"

End Sub

Private Sub mnupagesetup_Click()
psdlg.lStructSize = Len(psdlg)
psdlg.hwndOwner = hwnd
PageSetupDlg psdlg
End Sub

Private Sub mnuplaster_Click()
RichText.SelText = Clipboard.GetText(1)
End Sub

Private Sub mnuprint_Click()
Dim f As Integer, t As Integer
Dim i As Integer
CommonDialog1.CancelError = True
CommonDialog1.Max = 1000
CommonDialog1.Min = 1
On Error Resume Next
CommonDialog1.ShowPrinter

For f = CommonDialog1.FromPage To t = CommonDialog1.ToPage
Do While i < CommonDialog1.Copies + 1
Printer.Print RichText.Text
i = i + 1
Loop
Next
Printer.EndDoc
Cancel:
If Err.Number = 32755 Then
Exit Sub
End If
End Sub

Private Sub mnusave_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next
filename = CommonDialog1.filename '保存文件
If filename <> "" Then
RichText.SaveFile filename, rtfText
Else
mnusaveas_Click
End If
ask = False
End Sub

Private Sub mnusaveas_Click()
CommonDialog1.Filter = "文本文档(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next

CommonDialog1.ShowSave
filename = CommonDialog1.filename
RichText.SaveFile filename, rtfText

result = GetFileTitle(filename)
Me.Caption = "" & result & "-记事本"
ask = False
End Sub

Private Sub mnustatusbar_Click()
If mnustatusbar.Checked Then
StatusBar1.Visible = False
mnustatusbar.Checked = False
Else
StatusBar1.Visible = True
mnustatusbar.Checked = True
End If

End Sub

Private Sub mnutimedate_Click()
RichText.SelText = Format(Now, "h:mm ddddd")
End Sub

Private Sub mnuwordwrap_Click()
WrapTextLine RichText, bWrap
bWrap = Not bWrap
If mnuwordwrap.Checked = False Then
HScroll1.Enabled = True
mnuwordwrap.Checked = True

Else
HScroll1.Enabled = False
mnuwordwrap.Checked = False

End If

End Sub

Private Sub RichText_Change()
ask = True
End Sub

Private Sub Timer1_Timer()
If StatusBar1.Panels(1).Text <> CStr(Time) Then
StatusBar1.Panels(1).Text = Time
End If

End Sub

'模块代码

Option Explicit
Const WM_USER = &H400
Const EM_SETTARGETDEVICE = (WM_USER + 72)
Type POINTAPI
x As Long
y As Long
End Type
Type RECT
left As Long
right As Long
top As Long
bottom As Long
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Public psdlg As PageSetupDlg
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long

Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim bWrap As Boolean '// 换行标记'// 自定义一个换行的过程
Public Sub WrapTextLine(ByRef RichText As RichTextBox, ByVal bWrapSwitch As Boolean)
On Error Resume Next
If bWrapSwitch Then '// 设置 RichTextBox 自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, GetDC(RichText.hwnd), RichText.Width / 15
RichText.RightMargin = IIf(RichText.RightMargin = 0, 1, 0)
Else
'// 设置 RichTextBox 不自动换行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, 0, 1
End If
End Sub
Function GetFileTitle(OldStr As String) As String

On Error Resume Next
Dim n As Integer, m As Integer '声明字符串变量
Dim i As String, r As String
Dim p As Integer
i = "\" '要查找的指定字符
For n = 1 To Len(OldStr) '用Len函数计算已知字符串的字节数
m = InStrRev(OldStr, i, -1) '"\"所在的位置(其中的-1是默认的)
Next n '找下去!

'截取最后一个"\"后面的字符串
r = right(OldStr, Len(OldStr) - m) '获取Title
p = InStrRev(r, ".", -1) '"."所在位置
GetFileTitle = left(r, p - 1) '去掉后缀

End Function
温馨提示:内容为网友见解,仅供参考
第1个回答  2019-03-06
请确保commonDialog控件已拖放到form上,具体步骤为:在vb的project菜单下,打开components子菜单,在弹出窗口中的controls标签页下,找到Microsoft
Common
Dialog
?.0(SP?)打上勾后确定,确定之后在控件选择那个栏位表会出现一个新加入的图标,鼠标移上去会出现CommonDialog字样,将它点击拖入你建立的窗体上,再尝试运行
第2个回答  2020-03-28
没有在窗体添加
CommonDialog
控件
Ctrl+T,选择
microsoft
common
dialog..
再在工具箱中将其拖到窗体即可
第3个回答  2008-01-07
http://download.csdn.net/sort/tag/%E8%AE%B0%E4%BA%8B%E6%9C%AC%EF%BC%8Cvb%EF%BC%8C%E6%BA%90%E4%BB%A3%E7%A0%81

CSDN的下载 需要先注册会员 我下载过 基本实现记事本的需求
第4个回答  2008-01-07
以前做过.并不难实现,VB有个控件rich textbox,记事本的基本功能都能用它实现

VB编写记事本
If a = vbYes Then End End If End Sub Private Sub Command1_Click()Dir1.Visible = False Drive1.Visible = False m = Dir1.Path Command1.Visible = False b = MsgBox("你选的文件夹是:" & m, vbYesNo + vbDefaultButton1 + 48, "提示")If b = vbNo Then Dir1.Visible = ...

用VB制作一个简单记事本问题!
Private Sub cmd_Open_Click()Dim FileN$, FreeF%, T cmd_dlg.Filter = "文本文件(*.txt)|*.txt"cmd_dlg.CancelError = True On Error GoTo endsub cmd_dlg.ShowOpen FreeF = FreeFile FileN = cmd_dlg.FileName Open FileN For Input As FreeF Line Input #FreeF, T a_txt.Text...

我用VB写了个记事本的程序,这句代码 Open CommonDialog1.FileName...
Open CommonDialog1.FileName For Output As #1 以输出模式,打开通用对话框中选择的文件,文件号是1 Print #1,Text1 将文本框Text1中的文本,写入到文件号为1的文件中。

VB怎么打开记事本输入文字
Dim str As String Dim num As Integer Open "d:\\Myfile.txt" For Output As #1 str = “STUDY"num = 12345 Print #1, "Print输出:"Print #1, str, num Print #1, "***"Print #1, "Write输出:"Write #1, str, num Close #1 End Sub 记事本的效果如图:希望能帮到你!

vb制作记事本,新建代码怎么写
openfile(1,"名称.txt",output)closefile(1)

如果想在D盘里新建一个记事本,在VB的代码窗口里应如何写代码
有2种方法,一种是调用fso的流操作,另一种比较简单 dim filename as string filename="d:\\test.text"open filename for output as #1 print #1,"这里写入文件内容"close #1

怎样用vb打开记事本并在其中输入文字
双击Command2,加入下面的所有代码:Dim str1 As String,str2 As String str1=GetConfigString("Settings", "String1", "")str2=GetConfigString("Settings", "String2", "")if Text1.Text <> str1 Then msgbox "Text1中的内容与上次不同"else if text1.text<>str2 then msgbox "Text2...

怎样用VB制作类似于记事本里的查找对话框?
你可以自己做一个form1,在上面绘出text1用来输入关键字,还有别的按扭等控件。然后用下面语句查找:dim i as long i=instr(RichTextBox.text,text1.text)RichTextBox.selstart=i RichTextBox.sellength=len(text1.text)'这样就可以让RichTextBox自动选中要查找的关键字了。

VB记事本的保存代码
Private Function fSave(FilePath As String, fContent As String) As Boolen On Error GoTo saveErr Open FilePath For Output As #1 Print #1, fContent Close #1 fSave = True Exit Function saveErr:fSave = False End Function Private Sub Command1_Click() '保存按钮 Dim result As ...

怎么用vb做记事本
If KeyCode = vbKeySpace Then RichTextBox1.SelFontName = CommonDialog1.FontName End If End Sub 至此,我们的记事本可以编译使用了。点击菜单“文件”-“生成XXX.EXE”,回到桌面运行我们的记事本看看,是不是颇有成就感? 当然,这样的记事本还比较粗糙,我们还需要做些工作,请看下一章。 第二章 美化程序界面...

相似回答