记事本编写vb.net的简单介绍

怎样用vb.net做记事本??简单的 用TextBox 或者RichTextBox 控件啊至于文件 可以存为ANSIC编码的文本文件 或者数据库存取也行啊
怎么用VB.NET做一个记事本Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
RichTextBox1.LoadFile(Me.OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim fname As String
Me.SaveFileDialog1.ShowDialog()
fname = Me.SaveFileDialog1.FileName
If (fname"") Then
If (Me.OpenFileDialog1.FilterIndex = 1) Then
Me.RichTextBox1.SaveFile(fname, RichTextBoxStreamType.PlainText)
Else
Me.RichTextBox1.SaveFile(fname, RichTextBoxStreamType.RichText)
End If
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.SaveFileDialog2.ShowDialog()
If (Me.OpenFileDialog1.FileName"") Then
If (Me.OpenFileDialog1.FilterIndex = 1) Then
Me.RichTextBox1.SaveFile(Me.SaveFileDialog2.FileName, RichTextBoxStreamType.PlainText)
Else
Me.RichTextBox1.SaveFile(Me.SaveFileDialog2.FileName, RichTextBoxStreamType.RichText)
End If
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.FontDialog1.Font = Me.RichTextBox1.SelectionFont
If (Me.FontDialog1.ShowDialog() = Me.DialogResult.OK) Then
Me.RichTextBox1.SelectionFont = Me.FontDialog1.Font
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.ColorDialog1.Color = Me.RichTextBox1.SelectionColor
If (Me.ColorDialog1.ShowDialog() = Me.DialogResult.OK) Then
Me.RichTextBox1.SelectionColor = Me.ColorDialog1.Color
End If
End Sub
Private Sub 打开ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 打开ToolStripMenuItem.Click
Try
Dim str As String
Dim typel As System.Windows.Forms.RichTextBoxStreamType
OpenFileDialog1.ShowDialog()
str = OpenFileDialog1.FileName
RichTextBox1.LoadFile(str, RichTextBoxStreamType.PlainText)
Catch ex As Exception
End Try
End Sub
Private Sub 保存ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 保存ToolStripMenuItem.Click
Me.SaveFileDialog1.ShowDialog()
If (Me.SaveFileDialog1.FileName"") Then
If (Me.OpenFileDialog1.FilterIndex = 1) Then
Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
Else
Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)
End If
End If
End Sub
Private Sub 另存为ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 另存为ToolStripMenuItem.Click
Me.SaveFileDialog1.ShowDialog()
If (Me.OpenFileDialog1.FileName"") Then
If (Me.OpenFileDialog1.FilterIndex = 1) Then
Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
Else
Me.RichTextBox1.SaveFile(Me.SaveFileDialog1.FileName, RichTextBoxStreamType.RichText)
End If
End If
End Sub
Private Sub 退出ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 退出ToolStripMenuItem.Click
End
End Sub
Private Sub 字体ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 字体ToolStripMenuItem.Click
Me.FontDialog1.Font = Me.RichTextBox1.SelectionFont
If (Me.FontDialog1.ShowDialog() = Me.DialogResult.OK) Then
Me.RichTextBox1.SelectionFont = Me.FontDialog1.Font
End If
End Sub
Private Sub 颜色ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 颜色ToolStripMenuItem.Click
Me.ColorDialog1.Color = Me.RichTextBox1.SelectionColor
If (Me.ColorDialog1.ShowDialog() = Me.DialogResult.OK) Then
Me.RichTextBox1.SelectionColor = Me.ColorDialog1.Color
End If
End Sub
Private Sub SaveFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SaveFileDialog1.FileOk
End Sub
End Class
我用记事本编写了一个文件VB.net如何把生成可执行文件记事本编写vb.net你是在记事本中写的代码?把代码复制到vb.net环境下记事本编写vb.net,然后打包就行了,打包自己在网上查资料 , 不过建议你看书,书上比较详细,呵呵!
vb.net编写记事本richtextbox.find方法第二个参数值是介于0与0之间是什么意思?真巧,其实我也在写记事本哦,我写出来了查找的代码,你参考下
Private Sub 查找ToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles 查找ToolStripMenuItem.Click
'Dim fp As String
'fp = InputBox("请输入您要找的字符串", "寻找")
'If fp = "" Then
'MsgBox("您未输入字符串或者已取消!", MsgBoxStyle.Information)
'Else
'If InStr(RichTextBox1.Text, fp) Then
'Dim lines() As String = RichTextBox1.Lines
'Dim index As Integer = RichTextBox1.Find(fp, 0, RichTextBoxFinds.MatchCase)
'Dim targetline As Integer = RichTextBox1.GetLineFromCharIndex(index)
'Else
'MsgBox("未找到您输入的字符串!", MsgBoxStyle.Critical)
'End If
'End If
fp = InputBox("请输入您要找的字符串", "寻找")
If fp = "" Then
MsgBox("您未输入字符串或者已取消!", MsgBoxStyle.Information)
Else
If InStr(RichTextBox1.Text, fp) Then
Dim start As Integer = RichTextBox1.Find(fp, 0, RichTextBoxFinds.MatchCase)
If start = 0 Then
RichTextBox1.SelectionStart = start
RichTextBox1.SelectionLength = fp.Length
starta = startfp.Length1
Else
End If
Else
MsgBox("未找到您输入的字符串!", MsgBoxStyle.Critical)
End If
End If
End Sub
你试一下,我这里是可以运行的
用vb.net编写记事本源代码Dim sFileName As String
Dim Search
Private Sub dateTimeMenu_Click()
Text1.Text = Now
End Sub
Private Sub deleteMenu_Click()
Text1.Text = Left(Text1.Text, Text1.SelStart)Mid(Text1.Text, Text1.SelStartText1.SelLength1)
End Sub
Private Sub findMenu_Click()
Search = InputBox("请输入要查找的字词:")
Dim Where1 '获取需要查找的字符串变量
Text1.SetFocus '文本框获得焦点,以显示所找到的内容Search = InputBox("请输入要查找的字词:")
Where1 = InStr(Text1.Text, Search) '在文本中查找字符串
If Where1 Then
'若找到则设置选定的起始位置并使找到的字符串高亮
Text1.SelStart = Where1 - 1
Text1.SelLength = Len(Search)
' Me.Caption = Where1 '测试用
'否则给出提示
Else: MsgBox "未找到所要查找的字符串 。", vbInformation, "提示"
End If
End Sub
Private Sub findNextMenu_Click()
Dim Where2
Dim StartMe As Integer '查找的起始位置变量
Text1.SetFocus '文本框获得焦点
StartMe = Text1.SelLengthText1.SelStart1 '给变量赋值
Where2 = InStr(StartMe, Text1.Text, Search) '令其从上次找到的地方找起
If Where2 Then
Text1.SelStart = Where2 - 1
Text1.SelLength = Len(Search)
Else: MsgBox "未找到所要查找的字符串.", vbInformation, "提示"
End If
End Sub
Private Sub aboutMenu_Click()
MsgBox Space(2)"文本编辑器版本号1.0"Chr(13)"由西南财经大学天府学院"Chr(13)Space(5)"肖忠 开发"Chr(13)Space(2)"copyright:天府学院"
End Sub
Private Sub allMenu_Click()
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub backcolorMenu_Click()'设置背景色代码
Form1.CommonDialog1.Action = 3
Text1.BackColor = Form1.CommonDialog1.Color
End Sub
Private Sub colorMenu_Click()'改变文字颜色代码
Form1.CommonDialog1.Action = 3
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub cutMenu_Click()
Clipboard.SetText Text1.SelText
Text1.Text = Left(Text1.Text, Text1.SelStart)Mid(Text1.Text, Text1.SelStartText1.SelLength1)
End Sub
Private Sub exitMenu_Click()
End
End Sub
Private Sub fontMenu_Click()'字体菜单代码
Form1.CommonDialog1.Flags = 3 Or 256
Form1.CommonDialog1.Action = 4
If Len(Form1.CommonDialog1.FontName) = 0 Then
Form1.Text1.FontName = "宋体"
Else
Form1.Text1.FontName = Form1.CommonDialog1.FontName
End If
Form1.Text1.FontSize = Form1.CommonDialog1.FontSize
If Form1.CommonDialog1.FontBold = True Then
Form1.Text1.FontBold = True
Else
Form1.Text1.FontBold = False
End If
If Form1.CommonDialog1.FontItalic = True Then
Form1.Text1.FontItalic = True
Else
Form1.Text1.FontItalic = False
End If
Text1.ForeColor = Form1.CommonDialog1.Color
End Sub
Private Sub Form_Load()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub Form_Resize()
Form1.Text1.Width = Form1.Width - 130
Form1.Text1.Height = Form1.Height
End Sub
Private Sub help1Menu_Click()
Form1.CommonDialog1.HelpCommand = cdlHelpForceFile
Form1.CommonDialog1.HelpFile = "c:\windows\system32\winhelp.hlp"
CommonDialog1.ShowHelp
End Sub
Private Sub newMenu_Click()
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的记事本""--""未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋体"
Text1.Text = ""
Else
Call saveAsMenu_Click
Form1.Caption = "我的记事本""--""未命名"
sFileName = "未命名"
Text1.FontSize = 15
Text1.FontName = "宋体"
Text1.Text = ""
End If
End Sub
Private Sub openMenu_Click()'打开文件代码
If Len(Trim(Text1.Text)) = 0 Then
Form1.Caption = "我的记事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName)0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption"--"Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋体"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$Text$Chr(13)Chr(10)
Loop
Text1.Text = All
Close #1
End If
Else
Call saveAsMenu_Click
Form1.Caption = "我的记事本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 4096
Form1.CommonDialog1.Action = 1
If Len(Form1.CommonDialog1.FileName)0 Then
sFileName = Form1.CommonDialog1.FileName
Form1.Caption = Form1.Caption"--"Form1.CommonDialog1.FileTitle
Open sFileName For Input As #1
Text1.FontSize = 15
Text1.FontName = "宋体"
Do While Not EOF(1)
Line Input #1, Text$
All$ = All$Text$Chr(13)Chr(10)
Loop
【记事本编写vb.net的简单介绍】Text1.Text = All
Close #1
End If
End If
End Sub
Private Sub pasteMenu_Click()'粘贴菜单代码
Text1.Text = Left(Text1.Text, Text1.SelStart)Clipboard.GetText()Mid(Text1.Text, Text1.SelStartText1.SelLength1)
End Sub
Private Sub printMenu_Click()
Form1.CommonDialog1.ShowPrinter
For i = 1 To CommonDialog1.Copies
Printer.Print Text1.Text
Printer.Print Text1.Text
Next
Printer.EndDoc
End Sub
Private Sub saveAsMenu_Click()'另存为菜单代码
If Len(Trim(Text1.Text))0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName)0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub saveMenu_Click()
If Len(Trim(Text1.Text))0 Then
Form1.CommonDialog1.DialogTitle = "保存文件"
Form1.CommonDialog1.InitDir = "D:\"
Form1.CommonDialog1.FileName = "新建文本"
Form1.CommonDialog1.Filter = "文本文件|*.txt"
Form1.CommonDialog1.Flags = 2
Form1.CommonDialog1.ShowSave
If Len(Form1.CommonDialog1.FileName)0 Then
sFileName = Form1.CommonDialog1.FileName
Open sFileName For Output As #1
whole$ = Text1.Text
Print #1, whole
Close #1
End If
End If
End Sub
Private Sub statusMenu_Click()
End Sub
VB.NET写一个记事本程序,如何用程序让使用者编辑好的内容独立的存在硬盘上?你是说记事本的配置吧,
如果设置不是太大,可以保存在注册表中,
另外可以用xml文件或者ini文件来保存配置,
不知道有没理解错你的意思
记事本编写vb.net的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、记事本编写vb.net的信息别忘了在本站进行查找喔 。

    推荐阅读