vb.net記事本功能的簡(jiǎn)單介紹

用vb.net編寫記事本源代碼

Dim sFileName As String

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:域名與空間、網(wǎng)絡(luò)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、柳南網(wǎng)站維護(hù)、網(wǎng)站推廣。

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("請(qǐng)輸入要查找的字詞:")

Dim Where1 '獲取需要查找的字符串變量

Text1.SetFocus '文本框獲得焦點(diǎn),以顯示所找到的內(nèi)容Search = InputBox("請(qǐng)輸入要查找的字詞:")

Where1 = InStr(Text1.Text, Search) '在文本中查找字符串

If Where1 Then

'若找到則設(shè)置選定的起始位置并使找到的字符串高亮

Text1.SelStart = Where1 - 1

Text1.SelLength = Len(Search)

' Me.Caption = Where1 '測(cè)試用

'否則給出提示

Else: MsgBox "未找到所要查找的字符串。", vbInformation, "提示"

End If

End Sub

Private Sub findNextMenu_Click()

Dim Where2

Dim StartMe As Integer '查找的起始位置變量

Text1.SetFocus '文本框獲得焦點(diǎn)

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) "文本編輯器版本號(hào)1.0" Chr(13) "由西南財(cái)經(jīng)大學(xué)天府學(xué)院" Chr(13) Space(5) "肖忠 開發(fā)" Chr(13) Space(2) "copyright:天府學(xué)院"

End Sub

Private Sub allMenu_Click()

Text1.SelStart = 0

Text1.SelLength = Len(Text1.Text)

End Sub

Private Sub backcolorMenu_Click() '設(shè)置背景色代碼

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如何用我編寫的一個(gè)記事本程序通過(guò)鼠標(biāo)右鍵菜單來(lái)打開一個(gè)文件

一、用wshshell組件的RegWrite方法寫注冊(cè)表,在HKEY_CLASSES_ROOT\*\Shell 位置加入的你程序,

例如:

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

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

后面的%1會(huì)將文件名傳送給你的程序的Command$,多文件名需要使用DDE方式進(jìn)行互斥傳入。

二、

將下面內(nèi)容輸入記事本后保存為reg文件,運(yùn)行即可:

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中調(diào)用記事本和計(jì)算器

這個(gè)啊,呵呵,應(yīng)該不難吧

先找到你要打開的應(yīng)用程序的文件

然后用一個(gè)調(diào)用代碼:

System.Diagnostics.Process.Start("C:\WINDOWS\system32\notepad.exe")

這是要開記事本的

System.Diagnostics.Process.Start("C:\WINDOWS\system32\calc.exe")

這是打開計(jì)算器的

應(yīng)該也可以把這兩個(gè)應(yīng)用程序復(fù)制到你的程序的默認(rèn)目錄下,就是BIN下吧!

呵呵,試試!!要給我加分哦?。?!

VB.NET:想寫個(gè)代替WINDOWS里的“記事本”的軟件,可文本框有字?jǐn)?shù)限制,該怎么辦(2017年3月22)

如果.net的標(biāo)準(zhǔn)文本框都不夠長(zhǎng),那基本上不能用普通控件來(lái)解決了。因?yàn)闃?biāo)準(zhǔn)文本框內(nèi)容的長(zhǎng)度只受限于 String 的長(zhǎng)度,大約是2GB左右。如果它不行,那 RichTxetBox、Label 等都不行。

解決的方案:一個(gè)是讀文件時(shí)就判斷長(zhǎng)度,超長(zhǎng)的直接彈錯(cuò)即可。再一個(gè)是提示用戶將截?cái)?。再就是自己寫代碼,只讀取部分內(nèi)容供用戶查看和修改,當(dāng)用戶移動(dòng)滾動(dòng)條時(shí)再動(dòng)態(tài)的讀取相應(yīng)部分。最后這個(gè)當(dāng)然好,但難度也最大。

VB.net怎么才能實(shí)現(xiàn)記事本中的查找上一個(gè)的功能(在Richtextbox中)?

查找一次后記入查找內(nèi)容的位置,百查找下一個(gè)功能度 這時(shí)候的開始位置就是剛才查找內(nèi)容的位置加上查找內(nèi)容的長(zhǎng)度,版突出顯示其實(shí)就是選權(quán)定文本,富文本框有SelectionStart,SelectionLength 兩個(gè)屬性

關(guān)于VB.NET制作記事本自動(dòng)保存的問(wèn)題

經(jīng)過(guò)我的潛心修煉問(wèn)題終于是解決了.請(qǐng)看代碼

Imports System.IO

Private strFileName As String = "myRTFdoc.txt"

Private flgFirst As Boolean = True

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick

'如何將程序控制住,讓它第一次發(fā)現(xiàn)沒(méi)保存后,只擊活一次提示保存,然后使用修改后的保存路徑

Call zc()

End Sub

Private Sub zc()

'Timer2.Stop()

With SaveFileDialog1

.DefaultExt = "txt"

.FileName = strFileName

.Filter = "Text files(*.txt)|*.txt|All files(*.*)|*.*"

.FilterIndex = 1

.InitialDirectory = "c:\"

.OverwritePrompt = True

.Title = "Save Reminding"

End With

'Timer2.Enabled = False

If flgFirst = True Then

If SaveFileDialog1.ShowDialog = DialogResult.OK Then

strFileName = SaveFileDialog1.FileName

Dim objWriter As StreamWriter = New StreamWriter(strFileName, False)

objWriter.Write(rtbox.Text)

objWriter.Close()

objWriter = Nothing

End If

flgFirst = False

'Timer2.Enabled = True

' Timer2.Start()

Else

'flg= second

Dim objWriter As StreamWriter = New StreamWriter(strFileName, False)

objWriter.Write(rtbox.Text)

objWriter.Close()

objWriter = Nothing

End If

'Timer2.Enabled = True

'Timer2.Start()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Timer2.Enabled = True

' zc()

End Sub

知道問(wèn)題在哪里嘛?我調(diào)試了確實(shí)是"死循環(huán)"、其實(shí)不是真正的死循環(huán)、是time tick事件你設(shè)定的時(shí)間太短了.估計(jì)只設(shè)置了1-5s左右.那么程序運(yùn)行還需要時(shí)間.所以他就不停地調(diào)用timetick時(shí)間.你的savedialog對(duì)話框根本來(lái)不急彈出來(lái).

所以建議你把timer的interval的值設(shè)置高點(diǎn)最好12-15秒 觸發(fā)一次.

當(dāng)然我想還有其他的方法、還沒(méi)有徹底取研究下.

比如stop 什么 、那還需要時(shí)間.

至少目前我的方法是可以了.

我設(shè)置的12s P4. 3.0 1G 內(nèi)存 跑下我的程序如果 F10(F8)慢點(diǎn)的話就來(lái)不及了.

另為把你的程序小改了下、應(yīng)該可以滿足你的要求了.

本文題目:vb.net記事本功能的簡(jiǎn)單介紹
URL地址:http://muchs.cn/article20/doscejo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、虛擬主機(jī)網(wǎng)站改版、企業(yè)網(wǎng)站制作、定制網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)