我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net如何做记事本的简单介绍

用vb.net编写记事本源代码

Dim sFileName As String

南票网站建设公司成都创新互联,南票网站设计制作,有大型网站制作公司丰富经验。已为南票上1000家提供企业网站建设服务。企业网站搭建\成都外贸网站建设公司要多少钱,请找那个售后服务好的南票做网站的公司定做!

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.SelStart + Text1.SelLength + 1)

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.SelLength + Text1.SelStart + 1 '给变量赋值

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.SelStart + Text1.SelLength + 1)

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

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.SelStart + Text1.SelLength + 1)

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做记事本??

简单的 用TextBox 或者RichTextBox 控件啊 至于文件 可以存为ANSIC编码的文本文件 或者数据库存取也行啊

VB编写记事本

vb编写的简单记事本代码

Dim b As String

Dim a As String

Dim m As String

Dim x As String

Private Declare Function SetWindowPos Lib "user32" ( _

ByVal hwnd As Long, _

ByVal hWndInsertAfter As Long, _

ByVal x As Long, ByVal Y As Long, _

ByVal cx As Long, ByVal cy As Long, _

ByVal wFlags As Long _

) As Long

Const HWND_TOPMOST = -1

Const SWP_SHOWWINDOW = H40

Private Sub baocun_Click()

Dim abc As String

If Len(Trim(m)) = 0 Then

m = "f:"

End If

abc = m "\" Text2.Text ".txt"

Open abc For Output As #1

Write #1, Text1.Text

Close #1

Label2.Caption = "保存的路径为:" m "\" Text2.Text ".txt"

a = MsgBox("保存成功!" Chr(13) "是否退出程序", 4 + 64 + 0, "提示")

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 = True

Drive1.Visible = True

Command1.Visible = True

Else

Dir1.Visible = False

Drive1.Visible = False

Command1.Visible = False

End If

End Sub

Private Sub Command2_Click()

MsgBox (App.Path + "1.ico")

End Sub

Private Sub dakai_Click()

CommonDialog1.Filter = "文本文件(*.txt)|*.txt"

CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Input As #1

Dim abc As String

linefromfile = StrConv(InputB(LOF(1), 1), vbUnicode)

Text1.Text = linefromfile

Close #1

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive

End Sub

Private Sub Form_Load()

Drive1.Drive = "f:\"

Dir1.Visible = False

Drive1.Visible = False

Command1.Visible = False

Dim fullpath As String

If Right(App.Path, 1) = "\" Then

fullpath = App.Path + "1.ico"

Else

fullpath = App.Path + "\" + "1.ico"

Form1.Icon = LoadPicture(fullpath)

End If

End Sub

Private Sub lingcunwei_Click()

Dim abc As String

CommonDialog1.ShowSave

If Len(Trim(CommonDialog1.FileName)) 0 Then

x = CommonDialog1.FileName

Else

x = "f:\1.txt"

End If

Open x For Append As #1

Write #1, Text1.Text

Close #1

End Sub

Private Sub s_Click()

Text1.FontSize = 5

End Sub

Private Sub sanhao_Click()

Text1.FontSize = 12

End Sub

Private Sub st_Click()

CommonDialog1.ShowFont

End Sub

Private Sub shybcdwjj_Click()

Dir1.Visible = True

Drive1.Visible = True

Command1.Visible = True

End Sub

Private Sub Text2_GotFocus()

Dir1.Visible = False

Drive1.Visible = False

Command1.Visible = False

End Sub

Private Sub tuichu_Click()

End

End Sub

Private Sub wh_Click()

Text1.FontSize = 10

End Sub

Private Sub whs_Click()

Text1.FontSize = 10.5

End Sub

Private Sub xinjian_Click()

Text1.Text = ""

Text2.Text = ""

End Sub

Private Sub yh_Click()

Text1.FontSize = 24

End Sub

Private Sub zstj_Click()

MsgBox "所有字数为" Len(Text1.Text), , " 字数"

End Sub

Private Sub ztys_Click()

CommonDialog1.ShowColor

Text1.ForeColor = CommonDialog1.Color

End Sub

Private Sub zzqm_Click()

Dim retValue As Long

'将窗体设置为处于所有窗口的顶层,注意在 VB 中运行时,可能不行,但编译成EXE后就可以了

retValue = SetWindowPos(Me.hwnd, HWND_TOPMOST, Me.CurrentX, Me.CurrentY, 380, 615, SWP_SHOWWINDOW)

End Sub

vb.net如何用我编写的一个记事本程序通过鼠标右键菜单来打开一个文件

一、用wshshell组件的RegWrite方法写注册表,在HKEY_CLASSES_ROOT\*\Shell 位置加入的你程序,

例如:

[HKEY_CLASSES_ROOT\*\shell\我的程序\command]

@="D:\\我的程序.exe %1"

后面的%1会将文件名传送给你的程序的Command$,多文件名需要使用DDE方式进行互斥传入。

二、

将下面内容输入记事本后保存为reg文件,运行即可:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\OpenInNotepad]

@="用记事本打开"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\OpenInNotepad\command]

@="notepad.exe %1"

"用记事本打开" 为右键菜单中显示的名称

VB.NET做一个类似记事本的可执行文件,保存时不知道怎么用代码设置保存类型(文件扩展名)

算了,都贴上,你自己看吧:

//设置文件类型

//书写规则例如:txt files(*.txt)|*.txt

saveFileDialog.Filter = "txt files(*.txt)|*.txt|xls files(*.xls)|*.xls|All files(*.*)|*.*"

//设置默认文件名(可以不设置)

saveFileDialog.FileName = "siling-Data"

//主设置默认文件extension(可以不设置)

saveFileDialog.DefaultExt = "xml"

//获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)

saveFileDialog.AddExtension = true

//设置默认文件类型显示顺序(可以不设置)

saveFileDialog.FilterIndex = 2

//保存对话框是否记忆上次打开的目录

saveFileDialog.RestoreDirectory = true

怎么用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如何做记事本的简单介绍
URL标题:http://mswzjz.cn/article/dsiosio.html

其他资讯