Realize some source code similar to writing a writing program with VB.NET

zhaozj2021-02-11  216

'Welcome to communicate with me: luluhai@eastday.com

All source code is downloaded here: http://www.up2e.com/resource.php

'This program code is the job of VB.Net curriculum design' code writing and finishing: Luhai

Imports system.drawing.printingImports system.drawing.fontpublic class form inherits system.windows.forms.form

#Region "Windows Form Designer Generated Code"

Public Sub new () mybase.new ()

'This call is required for the Windows Form Designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting disposal to clean the component list. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer

'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents mFile As System.Windows.Forms.MenuItem Friend WithEvents mNew As System.Windows.Forms.MenuItem Friend WithEvents mOpen As System.Windows.Forms.MenuItem '..... ................ '.....................' ......... ............ 'Due to a long time, I will ignore him' ............... '........ ........ Me.Panel1.suspendlayout () me.suspendlayout () '' mainmenu1 'me.mainMenu1.Menuitems.addRange (new system.windows.forms.Menuitem () {me.mfile, me . milormat, me.mhelp} '' 'mfile' me.mfile.index = 0 me.mfile.Menuitems.addrange (new system.windows.forms.MenuItem () {me.mnew, Me.Mopen, Me.Msave, Me.msaveas, Me.Menuitem6, Me. MPrint, Me. Mprintpreview, me.mpagesetup, me.menuitem10, me.mexit} me.mfile.text = "file (& f)" 'mnew' me.mnew.index = 0 me.mnew.shortcut = system.windows.Forms.Shortcut.ctrln Me.mnew.text = "New (& N) ..." '' Mopen 'me.mopen.index = 1 me.mopen.shortcut = system.windows.forms.shortcut.ctrlo me.mopen.text = "Open ( & O) ... "'' msave 'me.msave.index = 2 me.msave.shortcut = system.windows.forms.shortcut.ctrls me.msave.text =" Save (& S) "' 'Msaveas' ME. Msaveas.index = 3 me.msaveas.text = "Save As (& A) ..." '' Menuitem6 'me.Menuitem6.index =

4 me.Menuitem6.text = "-" '' mprint 'me.mprint.index = 5 me.mprint.shortcut = system.windows.forms.shortcut.ctrlp me.mprint.text = "Print (& P) ... "'' MPrintPreview 'me.mprintpreview.index = 6 me.mprintpreview.text =" Print preview (& V) "' 'mpagesetup' me.mpagesetup.Index = 7 me.mpagesetup.text =" page settings (& U) .. "'' Meneuitem10 'me.Menuitem10.index = 8 me.Menuitem10.text =" - "' 'mexit' me.mexit.index = 9 me.mexit.text =" Exit (& X) '' MEDIT 'ME . desmedit.index = 1 me.medit.menuitems.addrange (new system.windows.forms.Menuitem () {me.mundo, me.Menuitem1, Me.mcut, me.mcopy, me.mpaste, me.mclear, me .mselectall, me.menuitem21, me.mfind, me.mfindnext, me.mreplace}) me.medit.text = "Edit (& E)" '' 'Mundo' me.mundo.index = 0 me.mundo.shortcut = SYSTEM .Wind OWS.FORMS.SHORTCUT.CTRLZ me.mundo.text = "Undo (& U)" '' menuitem1 'me.Menuitem1.index = 1 me.Menuitem1.text = "-"' 'mcut' me.mcut.index = 2 Me.mcut.shortcut = system.windows.Forms.shortcut.ctrlx me.mcut.text = "Cut (& T) '' '' McOPY 'me.mcopy.index = 3 me.mcopy.shortcut =

System.Windows.Forms.Shortcut.ctrlc me.mcopy.text = "Copy (& C)" '' 'mpaste' me.mpaste.index = 4 me.mpaste.shortcut = system.windows.forms.shortcut.ctrlp me.mpaste .Text = "Paste (& P)" '' mclear 'me.mclear.index = 5 me.mclear.shortcut = system.windows.mclear.text = "Clear (& A)' 'MSelectAll 'Me.mselectall.index = 6 me.mselectall.shortcut = system.windows.forms.shortcut.ctrla me.mselectall.text = "All Choice (& L)"' 'me.Menuitem21.index = 7 me.Menuitem21 .Text = "-" '' mfind 'me.mfind.index = 8 me.mfind.shortcut = system.windows.forms.shortcut.ctrlf me.mfind.text = "Find (& f) ..."' 'mfindnext 'Me.mfindnext.index = 9 me.mfindnext.shortcut = system.windows.forms.shortcut.f3 me.mfindnext.text = "Find Next (& n)"' MREPL ACE 'me.mreplace.index = 10 me.mreplace.shortcut = system.windows.Forms.Shortcut.ctrlh me.mreplace.text = "Replace (& E) ..."' 'mview' me.mview.index = 2 Me.mview.MenuItems.addrange (new system.windows.forms.MenuItem () {me.mstatusbar}) me.mview.text = "View (& V)" '' mstatusbar 'me.mstatusbar.checked = true me.mstatusbar .Ind =

0 me.mstatusbar.text = "Status Bar (& S)" '' mformat 'me.mformat.index = 3 me.mformat.Menuitems.Addrange (new system.windows.forms.MenuItem () {me.mfont, me. Menuitem2}) Me.mformat.Text = "Format (& D) '' MFONT 'M.MFONT.IDEX = 0 me.mfont.text =" Font (& f) ... "' 'Menuitem2' Me.Menuitem2.index = 1 me.Menuitem2.text = "Color (& C) ..." '' MHELP 'me.mhelp.index = 4 me.mhelp.Menuitems.addrange (new system.windows.forms.Menuitem () {me.mhelptopics , Me.Menuitem34, Me.mabout}) Me.mHelp.Text = "Help (& H)" '' MHELPTOPICS 'Me.mhelptopics.Index = 0 me.mhelptopics.text = "Help Topics (& H)"' 'MenuItem34' Me.Menuitem34.index = 1 me.Menuitem34.text = "-" '' mabout 'me.mabout.index = 2 me.mabout.text = "About this writing panel job (& a)"' SaveFileDialog1 'me.s AvefileDialog1.FileName = "DOC1" '' Toolbar1 'me.toolbar1.allowdrop = true me.toolbar1.autosize =

False Me.ToolBar1.Buttons.AddRange (New System.Windows.Forms.ToolBarButton () {Me.tbbNew, Me.tbbOpen, Me.tbbSave, Me.ToolBarButton1, Me.ToolBarButton2, Me.vbbPrint, Me.tbbPreview, Me. ToolBarButton3, Me.ToolBarButton4, Me.tbbFind, Me.ToolBarButton5, Me.ToolBarButton6, Me.tbbCut, Me.tbbCopy, Me.tbbPaste, Me.tbbUndo}) Me.ToolBar1.ButtonSize = New System.Drawing.Size (25, 24) Me.ToolBar1.DropDownArrows = True Me.ToolBar1.ImageList = Me.ImageList1 Me.ToolBar1.Name = "ToolBar1" Me.ToolBar1.ShowToolTips = True Me.ToolBar1.Size = New System.Drawing.Size (688, 32 ) Me.toolbar1.tabindex = 0 '' tbbnew 'me.tbbNew.ImageIndex = 5 me.tbbnew.tooltiptext = "New"' 'TBBopen' me.tbbopen.iMageIndex = 6 me.tbbopen.tooltiptext = "Open" ' Tbbsave 'me.tbbsave.imageindex = 10 me.tbbsave.tooltiptext = "Save"' 'ToolbarButton1' ME. ToolBarButton1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator '' ToolBarButton2 'Me.ToolBarButton2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator' 'vbbPrint' Me.vbbPrint.ImageIndex = 9 Me.vbbPrint.ToolTipText = " Print "'' tbpreview 'me.tbbpreview.imageIndex = 8 me.tbbpreview.tooltiptext =" Print preview "' 'ToolbarButton3' me.toolbarbutton3.style =

System.Windows.Forms.ToolBarButtonStyle.Separator '' ToolBarButton4 'Me.ToolBarButton4.Style = System.Windows.Forms.ToolBarButtonStyle.Separator' 'tbbFind' Me.tbbFind.ImageIndex = 12 Me.tbbFind.ToolTipText = "Find" ' ToolBarButton5 'Me.ToolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator' 'ToolBarButton6' Me.ToolBarButton6.Style = System.Windows.Forms.ToolBarButtonStyle.Separator '' tbbCut 'Me.tbbCut.ImageIndex = 4 Me.tbbCut .ToolTipText = "cut" '' tbbCopy 'Me.tbbCopy.ImageIndex = 3 Me.tbbCopy.ToolTipText = "copy"' 'tbbPaste' Me.tbbPaste.ImageIndex = 7 Me.tbbPaste.ToolTipText = "paste" '' tbbUndo 'Me.tbbundo.imageindex = 11 me.tbbundo.tooltiptext = "Undo"' 'ImageList1' me.imagelist 1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit Me.ImageList1.ImageSize = New System.Drawing.Size (16, 16) Me.ImageList1.ImageStream = CType (resources.GetObject ( "ImageList1.ImageStream"), System .Windows.forms.imagelistStreamer) me.imagelist1.transparentcolor = system.drawing.color.transparent '' rtbox 'me.rtbox.anchor =

(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _ Or System.Windows.Forms.AnchorStyles.Left) _ Or System.Windows.Forms.AnchorStyles.Right) Me.rtbox .Font = new system.drawing.font ("Song", 9.0 !, system.drawing.fontstyle.regular, System.drawing.graphicsUnit.point, ctype (134, byte)) Me.rtbox.location = new System.drawing .Point (0, 64) me.rtbox.name = "RTBOX" me.rtbox.size = new system.drawing.size (688, 424) me.rtbox.tabindex = 3 me.rtbox.text = "" ' PrintDialog1 'Me.PrintDialog1.Document = Me.PrintDocument1' 'comboxFont' Me.comboxFont.Font = New System.Drawing.Font ( "Arial", 9.0 !, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point , Ctype (134, byte)) Me.comboxfont.location = new system.drawing.point (184, 40) me.comboxfont.name = "comboxfont" me.comboxfont.size = new system.drawing.size (121, 20) me.comboxfont.tabindex = 5 me.comBoxFont.text = "Font" '' ComboXsize 'me.comboxsize.items.addrange (new object () {"8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "26", "28", "36", "48", "72 "}) Me.comboxsize.location = new system.drawing.point (304, 40) me.comboxsize.name =" comboxsize "me.comboxsize.size = new system.drawing.size (48, 20) me.comboxsize. TabINDEX =

6 Me.comboxSize.Text = "Size" '' tbbbold 'Me.tbbbold.ImageIndex = 0 Me.tbbbold.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton Me.tbbbold.ToolTipText = "bold"' 'tbbi' Me.tbbi.ImageIndex = 1 Me.tbbi.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton Me.tbbi.ToolTipText = "italic" '' tbbu 'Me.tbbu.ImageIndex = 2 Me.tbbu.Style = System. Windows.Forms.ToolbarButtonStyle.ToggleButton Me.Tbbu.Tooltiptext = "Underline" '' tbbcolor 'me.tbbcolor.imageIndex = 16 me.tbbcolor.tooltiptext = "This is color! Because it is not found.

" '' ToolBarButton8 'Me.ToolBarButton8.Style = System.Windows.Forms.ToolBarButtonStyle.Separator' 'ToolBarButton7' Me.ToolBarButton7.Style = System.Windows.Forms.ToolBarButtonStyle.Separator '' tbbleft 'Me.tbbleft.ImageIndex = 13 Me.tbbleft.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton Me.tbbleft.ToolTipText = "left" '' tbbmiddle 'Me.tbbmiddle.ImageIndex = 15 Me.tbbmiddle.Style = System.Windows.Forms.ToolBarButtonStyle. ToggleButton Me.tbbmiddle.ToolTipText = "against the" '' tbbright 'Me.tbbright.ImageIndex = 14 Me.tbbright.Style = System.Windows.Forms.ToolBarButtonStyle.ToggleButton Me.tbbright.ToolTipText = "right"' 'ToolBar2 'Me.tofbar2.buttons.addrange (new system.windows.forms.toolbarbutton () {me.tbbbu, me.tbbcolor, me.toolbarbutton8, me.toolbarb utton7, Me.tbbleft, Me.tbbmiddle, Me.tbbright}) Me.ToolBar2.ButtonSize = New System.Drawing.Size (23, 22) Me.ToolBar2.DropDownArrows = True Me.ToolBar2.ImageList = Me.ImageList1 Me. Toolbar2.location = new system.drawing.point (0, 32) me.toolbar2.name = "Toolbar2" me.toolbar2.showtooltips = true me.toolbar2.size = new system.drawing.size (688, 25) ME. Toolbar2.tabindex = 7 '' statusbar1 'me.statusbar1.location =

New system.drawing.point (0, 467) me.statusbar1.name = "statusbar1" me.statusbar1.size = new system.drawing.size (688, 22) me.statusbar1.tabindex = 8 '' panel1 'me. Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle Me.Panel1.Controls.AddRange (New System.Windows.Forms.Control () {Me.PictureBox1, Me.closepanel, Me.Label1, Me.mpreplace, Me. Findnext, me.find, me.rpbox, me.txtbox} me.panel1.location = new system.drawing.point (192, 160) me.panel1.name = "Panel1" me.Panel1.size = new system. Drawing.Size (272, 96) Me.Panel1.TabIndex = 9 Me.Panel1.Visible = False '' PictureBox1 'Me.PictureBox1.Image = CType (resources.GetObject ( "PictureBox1.Image"), System.Drawing.Bitmap ) Me.PictureBox1.Location = new system.drawing.point (8, 8) me.picturebox1.name = "PictureBox1" me.picturebox1.size = new system.drawing.size (16) Me.PictureBox1.tabind ex = 7 Me.PictureBox1.TabStop = False '' closepanel 'Me.closepanel.Font = New System.Drawing.Font ( "Arial", 9.0 !, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, Ctype (134, byte)) Me.ClosePanel.ForeColor = system.drawing.color.black me.closepanel.location = new system.drawing.point (240, 64) me.closePanel.name = "ClosePanel" me.closepanel. Size = new system.drawing.size (24, 24) me.closepanel.tabindex = 6 me.closepanel.text = "Off" '' Label1 '

Me.Label1.Location = new system.drawing.point (24, 8) me.label1.name = "label1" me.label1.size = new system.drawing.size (61, 16) me.label1.tabindex = 5 Me.Label1.Text = "Find - Dragon" '' mpreplace 'me.mpreplace.location = new system.drawing.poperty (112, 64) me.mpreplace.name = "mpreplace" me.mpreplace.size = new system .Drawing.size (72, 23) me.mpreplace.tabindex = 4 me.mpreplace.text = "replace" '' findnext 'me.findnext.location = new system.drawing.point (192, 32) Me.FindNext. Name = "findnext" me.findnext.tabindex = 3 me.findnext.text = "Next" 'Find' me.find.location = new system.drawing.point (112, 32) me.find.name = " Find "me.find.size = new system.drawing.size (72, 23) me.find.TabINDEX = 2 me.find.text =" Find "'' rpbox 'me.rpbox.location = new system.drawing. Point (8, 64) ME.RP Box.name = "rpBox" me.rpbox.tabindex = 1 me.rpbox.text = "" 'txtbox' me.txtbox.location = new system.drawing.point (8, 32) me.txtbox.name = " TXTBOX "Me.txtBox.tabINDEX = 0 me.txtbox.text =" "'Formmain' me.adeoscalebasesize = new system.drawing.size (6, 14) me.clientsize =

New system.drawing.size (688, 489) Me.Controls.addrange (new system.windows.forms.control () {me.panel1, me.statusbar1, me.comboxsize, me.comboxfont, me.toolbar2, me. RTBOX, Me.Toolbar1}) Me.icon = ctype (Resources.GetObject ("$ this.icon"), system.drawing.icon) me.Menu = me.mainMenu1 me.name = "form" me.text = " VB.NET course design job 2 - Word board :::::.

#End region

'Declare a global Boolean variable to mark the text changes and save in Richtextbox Dim Bsave as boolean

'The following program is used to initialize the dialog attribute and global variables. PRIVATE SUB FORMMAIN_LOAD (Byval e as system.Object, byval e as system.eventargs) Handles mybase.load' for BSAVE first assignment bsave = true ' initializes SaveFileDialog1.FileName as savefiledialog = "" SaveFileDialog1.DefaultExt = "txt" SaveFileDialog1.Filter = "Text files (* .txt) | * .txt | All files (* *.) |. * *" SaveFileDialog1.Title = "Save file .." initialization OpenFiledialog1.FileName = "" OpenFiledialog1.defaultExt = "txt" openfiledialog1.filter = "text files (* .txt) | * .txt | all files (*. *) | * "OpenFileDialog1.title =" Open file .. "'The following code is loaded in all fonts in the local system to Combob /fonts as Fontfamily for Each Allfonts in System.drawing.FontFamily.Families Comboxfont.Itemily.add (Allfonts .Name) Next End Sub

Private Sub RTBOX_TEXTCHANGED (BYVAL E AS Object, BYVAL E AS ITEM.EVENTARGS) Handles RTBOX.TEXTCHANGED 'The text has changed, and the variable BSAVE is set to false bsave = false end sub' *********** *********************************************************** *******************************

'The following function is used to remove the font styles specified by the user, such as bold, underscore, etc. Public Sub RemoveFontStyle (ByVAL RTB as RichtextBox, _ Byval Style as system.drawing.fontstyle)' If the length of the text is greater than 0, A removal pattern. 'This is very necessary! Because there may be many different styles in the selected text, and our originality is' Keep all the original style, except that the style IF RTB.SelectionLength> 0 Then Dim sleelStart AS Integer = RTB.SelectionStart Dim SelLength As INTEGER = RTB.SelectionLength Dim Currfont as system.drawing.font dim currsty as system.drawing.fontstyle

DIM I as integer for i = 0 to selLength - 1 'Select a character RTB.Select (SELSTART I, 1)' to get the character of the selected character's font currfont = RTB.SelectionFont 'to get the selected character, while removing Removed style currsty = currfont.style currsty = currsty and not style 'then gives these characters new fonts and styles RTB.SelectionFont = New font (currfont.fontfamily, currfont.size, _ currsty) Next' to stay originally selected RTB.Select (SELSTART, SELLENGTH) Else RTB.SelectionFont = New font (RTB.SelectionFont, _ RTB.SeLectionFont.Style and not style) end if End Sub

'The following function is used to increase the style of the font, such as bold, underscore, etc. Public Sub AddFontStyle (ByVal Style as system.drawing.fontstyle)' If the selected text is greater than 0, one will be Character adds styles. 'This is very necessary! Because the selected characters may contain a variety of styles,' and our originality is just to keep all the original style, add the specified style if rtb.seectionLength> 0 Then Dim SELSTART AS integer = r = RTB .SelectionStart Dim Sellength as integer = rtb.selectionLength Dim Currfont as system.drawing.font dim currsty as system.drawing.fontstyle

DIM I as integer for i = 0 TO SELLENGTH - 1 'Select character RTB.Select (SELSTART I, 1)' Get the font of the selected character currfont = RTB.SelectionFont 'get the current style, while adding the specified style Currstyle = currfont.style currsty = currstyle or style 'then enables characters to have new fonts and new styles, there is an exception,' Because not all stylus supports all styles, so capture exception Try RTB.SelectionFont = New font Currfont.fontfamily, currfont.size, _ currsty) catch exception end next next

RTB.Select (SELSTART, SELLENGTH) Else RTB.SelectionFont = New font (RTB.SelectionFont, _ RTB.SelectionFont.Style or Style) End if End Sub

'Not all fonts support all styles, the following function is used to check if the new font supports the style of choice. If you don't support it, remove the style' to use: getsafestyleForfontFamily (RichtextBox1.selectriTFont.FontFamily, RichTextBox1. SelectionFont.Style) Public Function GetSafeStyleForFontFamily (ByVal fontFam As FontFamily, _ ByVal style As FontStyle) As FontStyle 'remove the unsupported styles If (style And FontStyle.Regular) = FontStyle.Regular Then If not fontFam.IsStyleAvailable (FontStyle.Regular ) Then style = style And Not FontStyle.Regular End If End If If (style And FontStyle.Bold) = FontStyle.Bold Then If Not fontFam.IsStyleAvailable (FontStyle.Bold) Then style = style And Not FontStyle.Bold End If End If If (style And FontStyle.Italic) = FontStyle.Italic Then If Not fontFam.IsStyleAvailable (FontStyle.Italic) Then style = style And Not FontStyle.Italic End If End If If (style And FontStyle.Underline) = FontStyle.Und erline Then If Not fontFam.IsStyleAvailable (FontStyle.Underline) Then style = style And Not FontStyle.Underline End If End If If (style And FontStyle.Strikeout) = FontStyle.Strikeout Then If Not fontFam.IsStyleAvailable (FontStyle.Strikeout) Then style = Style and not fontstyle.strikeout End If Endstyle.strike End Function 'Below this setfontsize function is used to set the size of the font. Public SUB SetFontSize (Byval Fontsize As Single)

IF RTB.SelectionLength> 0 Then Dim SELSTART AS INTEGER = RTB.SelectionStart Dim Sellength As Integer = RTB.SerectionLength Dim Currfont As System.drawing.Fontdim i as Integer for i = 0 to Sellength - 1

RTB.SELECT (SELSTART I, 1)

Currfont = RTB.SelectionFont

RTB.SelectionFont = New font (currfont.fontfamily, fontsize, _ currfont.style) Next

RTB.Select (SELSTART, SELLENGTH) Else RTB.SelectionFont = New font (RTB.SelectionFont.Name, Fontsize, _ RTB.SeLectionFont.Style) end if End Sub

'The following function is used to set the font SetFontFamily change Public Sub SetFontFamily (ByVal rtb As RichTextBox, ByVal fontName As String) Dim fontFam As New System.Drawing.FontFamily (fontName) Dim style As System.Drawing.FontStyle

If RTB.SerectionLength> 0 Then Dim SELSTART AS INTEGER = RTB.SelectionStart Dim SelLength As INTEGER = RTB.SEELECTIONLENGTH

DIM I as integer for i = 0 to SelLength - 1

RTB.SELECT (SELSTART I, 1)

Style = getsafestyleforfontfamily (fontfam, rtb.selectionfont.style)

RTB.SelectionFont = New font (fontfam, rtb.seectionfont.size, style) Next

RTB.Select (SELSTART, SELLENGTH) ELSE

Style = getsafestyleforfontfamily (fontfam, rtb.selectionfont.style)

RTB.SelectionFont = New font (fontfam, rtb.selectionfont.size, style) end if End Sub

'********************************************************** *****************************************

'The function below is used to create a new file private sub newfile () DIM flag as integer' If the text has been saved, clear the rtbox content, all variables are reset to create a new text if bsave dam, quear () savefiledialog1.filename = " "BSAVE = true else" If the text is not saved, the prompt is to save Flag = messagebox.show ("File content has changed, want to save file ??", "info", messageboxibuttons.yesnocancel, messageboxicon.information Select Case Flag 'Case 6 is when the user selects "Save", executes the save file, if the file name is not selected, the save dialog box will pop up, and the user selects the file name to save after saving text if SavefileDialog1 .FileName = "" then If SaveFileDialog1.ShowDialog then rtbox.SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If Else 'If you have chosen to save the file name, then save the text to a file rtbox.SaveFile (SaveFileDialog1.FileName , RichtextBoxStreamType.plaintext) end if 'then Clear the contents of RTBOX, reset the variable to create a new text bsave = true rtbox.clear () savefiledialog1.FileName = "" Case 7 is when the user chooses NO, it is not saved, immediately empties RTBOX content, reset the variable to create new Text Case 7 rtbox.clear () SaveFileDialog1.FileName = "" BSAVE = true

'Case Else is when the user selects the cancellation, then cancel the new operation, that is, do Nothing Case Else End Select End If End Sub

'The following function is used to open the file private sub OpenFile () DIM FLAG AS INTEGER' If the text content is not saved, ask the user to save if NOT BSAVE THEN FLAG = MessageBox.show ("File content has changed, want to save the file? "" Info ", MessageBoxCon.information Select Case Flag 'Case 6 is when the user selects" Save ", execute the save file Case 6' If you do not select the file name you want to save, then pop up save dialog box, select the user to save the file name to save the text If SaveFileDialog1.FileName = "" Then If SaveFileDialog1.ShowDialog Then rtbox.SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If Else 'If you have chosen to save file name, then save the text to a file rtbox.SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End if 'open file dialog box pops up, opened the file operation bSave = True if OpenFileDialog1.ShowDialog () = DialogResult.OK then rtbox.LoadFile (OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If'case 7 means that if the user selects "Do not Save", then open the file directly perform operations Case 7 If OpenFileDialog1.ShowDialog () = DialogResult.OK Then rtbox. LoadFile (OpenFileDialog1.FileName, RichtextBoxStreamType.Plaintext) end if Bsave = true

'Case Else is also the user chooses to cancel Case Else End Select

'Else text has been saved, the file open operation is directly performed Else If OpenFileDialog1.ShowDialog () = DialogResult.OK Then rtbox.LoadFile (OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If bSave = True End If End Sub' The following functions are used To save the file private sub savefile (), if you do not select the file name you want to save, the Save Dialog box will pop up, and save the text if SavefileDialog1.ShowDialog Then RTBOX by the user to save the file name you want to save. SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If Else 'If you have chosen to save the file name, then save the text to a file rtbox.SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If bSave = True End Sub

'********************************************************** *************************** "Print, Print Preview

'Must determine that all print events are for the same printDocument private withevents pdoc as new printDocument ()

'Print file is a function of printing events, whenever you want to print, this event is triggered' below is a very fast and useful precision calculation to print text can be included to the entire print page 'is I am from Microsoft Site data obtained on, I apply it to my program Private Sub pdoc_PrintPage (ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage 'Declare a variable to hold the position of the last printed Char. Declare 'As Static So That Subsequent PrintPage Events Can Reference It. Static Intcurrentchar as Int32' Initialize The Font to Be Used for Printing. Dim Font AS New Font ("Microsoft Sans Serif", 24)

. Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32 With pdoc.DefaultPageSettings 'Initialize local variables that contain the bounds of the printing' area rectangle intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom intPrintAreaWidth = .PaperSize. Width - .Margins.Left - .Margins.Right 'Initialize local variables to hold margin values ​​that will serve' as the X and Y coordinates for the upper left corner of the printing 'area rectangle marginLeft = .Margins.Left.' X coordinate Margintop = .MARGINS.TOP 'Y COORDINATE End with

'If the user selected Landscape mode, swap the printing area height' and width. If pdoc.DefaultPageSettings.Landscape Then Dim intTemp As Int32 intTemp = intPrintAreaHeight intPrintAreaHeight = intPrintAreaWidth intPrintAreaWidth = intTemp End If

'Calculate the total number of lines in the document based on the height of' the printing area and the height of the font. Dim intLineCount As Int32 = CInt (intPrintAreaHeight / font.Height) 'Initialize the rectangle structure that defines the printing area. Dim RectPrintingarea As New Rectanglef (Marginleft, Margintop, INTPRINTAREAWIDTH, INTPRINTAREAHET)

'Instantiate the StringFormat class, which encapsulates text layout' information (such as alignment and line spacing), display manipulations' (such as ellipsis insertion and national digit substitution) and OpenType 'features. Use of StringFormat causes MeasureString and DrawString to use' only an integer number of lines when printing each page, ignoring partial 'lines that would otherwise likely be printed if the number of lines per' page do not divide up cleanly for each page (which is usually the case). 'See further discussion in the SDK documentation about StringFormatFlags. Dim fmt As New StringFormat (StringFormatFlags.LineLimit) 'Call MeasureString to determine the number of characters that will fit in' the printing area rectangle. The CharFitted Int32 is passed ByRef and used 'later when calculating intCurrentChar and thus HasMorePages Linesfilled 'Is Not Needed for this Sample but must be passed when passing CharsFitted. 'Mid is used to pass the segment of remaining text left off from the' previous page of printing (recall that intCurrentChar was declared as' static. Dim intLinesFilled, intCharsFitted As Int32 e.Graphics.MeasureString ( Mid (rtbox.Text, intCurrentChar 1), font, _ New SizeF (intPrintAreaWidth, intPrintAreaHeight), fmt, _ intCharsFitted, intLinesFilled) 'Print the text to the page. e.Graphics.DrawString (Mid (rtbox.Text, intCurrentChar 1), font, _ brushes.black, recrintingarea, fmt)

'Advance the current char to the last char printed on this page. As' intCurrentChar is a static variable, its value can be used for the next' page to be printed. It is advanced by 1 and passed to Mid () to print the 'next page (see above in MeasureString ()). intCurrentChar = intCharsFitted' HasMorePages tells the printing module whether another PrintPage event 'should be fired. If intCurrentChar

Private sub printpreview () DIM PPD as new printpreviewDialog () try ppd.document = pdoc PPD.ShowDialog () catch exp as exception messageBox.show ("There is an error happened !! Can't preview!" & _ "Confident now you can" & _ "Connect to a printer?" & _ "Then preview can you.", Me.text, _ messageboxbuttons.ok, messageboxicon.Error) End er

Private sub mprintpreview_click (byvale as system.Object, byval e as system.eventargs) Handles MPrintpreview.click PrintPreview () end sub

Private Sub mPagesetup_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mPagesetup.Click Dim psd As New PageSetupDialog () With psd .Document = pdoc .PageSettings = pdoc.DefaultPageSettings End With

IF psd.showdialog = DialogResult.ok the pdoc.defaultpagesettings = psd.pagesettings end if End subprivate subprintfile () DILOG As new PrintDialog () Dialog.document = PDOC

IF Dialog.ShowDialog = DialogResult.ok kiln pdoc.print () end if End sub '****************************************** ********************************************************

Private sub mnew_click (byval e as system.Event, byval e as system.eventargs) handles mnew.click newfile () end SUB

Private Sub Mopen_Click (Byval E AS System.Object, Byval E AS System.EventArgs) Handles Mopen.Click OpenFile () End Sub

Private sub msave_click (byval e as system.EventArgs) handles msave.click savefile () end sub

Private Sub mSaveas_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mSaveas.Click 'to save the file window title to "Save File As" SaveFileDialog1.Title = "Save File As" If SaveFileDialog1.ShowDialog () = DialogResult.ok the rtbox.savefile (SavefileDialog1.FileName, RichtextBoxStreamType.plaintext) BSAVE = true endiff = "Save File" end subtitable

Private Sub Mexit_Click (Byval E AS System.EventArgs) Handles Mexit.Click 'Exit Operation Close () end SUB

'Before closing the program determines whether the text needs to be saved Private Sub formMain_Closing (ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If bSave = False Then Dim flag As Integer flag = MessageBox.Show ( "File Content has been changed, want to save file ?? "," info ", messageboxbuttons.yesno, messageboxicon.information Select Case Flag 'Case 6 is when the user selects" Save ", execute the save file Case 6' if not select the name of the file to be saved, the save dialog box pops up, save the text if SaveFileDialog1.FileName after selected by the user to save the file name = "" then if SaveFileDialog1.ShowDialog then rtbox.SaveFile (SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText) End If Else 'If you have selected the file name to be saved, save the text into the file rtbox.savefile (savefiledialog1.filename, richtextboxstreamtype.plaintext) End if case else' does not save End Select End If End Sub 'About Displaying the Code Sub Mabout_Click (Byval E AS System.Object, Byval E as System.EventArgs) Handles Mabout.Click' first needs to define a "About" instance Dim Fabout as new FormaBout () 'Shows His found.show () End Sub

Private Sub mFont_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mFont.Click If FontDialog1.ShowDialog () = DialogResult.OK Then rtbox.Font = FontDialog1.Font End If End Sub

Private Sub Mundo_Click (Byval e as system.EventArgs) Handles Mundo.click RTBOX.UNDO () End Sub

Private Sub mCut_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mCut.Click rtbox.Cut () End SubPrivate Sub mCopy_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mCopy.Click RTBOX.copy () End Sub

Private sub mpaste_click (Byval e as system.eventargs) handles mpaste.click rtbox.paste () end sub

Private sub mclear_click (Byval e as system.Object, byval e as system.eventargs) handles mclear.click rtbox.clear () End Sub

Private sub mselectall_click (Byval E AS System.EventArgs) Handles Mselectall () end subselectall () end sub

Private Sub ToolBar1_ButtonClick (ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Select Case ToolBar1.Buttons.IndexOf (e.Button) Case 0 newfile () Case 1 openfile () Case 2 Savefile () case 5 printfile () case 6 printpreview () case 9 panel1.visible = true case 12 rtbox.cut () case 13 rtbox.copy () case 14 rtbox.paste () Case 15 rtbox.undo ()

End Select End Sub

Private sub mprint_click (Byval e as system.EventArgs) Handles mprint.click printfile () end sub

Private Sub comboxFont_SelectedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboxFont.SelectedIndexChanged SetFontFamily (rtbox, comboxFont.Text) End Sub

Private Sub comboxSize_SelectedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboxSize.SelectedIndexChanged SetFontSize (rtbox, comboxSize.SelectedItem) End SubPrivate Sub ToolBar2_ButtonClick (ByVal sender As System.Object, ByVal e As System.Windows.Forms .ToolBarButtonClickEventArgs) Handles ToolBar2.ButtonClick Select Case ToolBar2.Buttons.IndexOf (e.Button) Case 0 If tbbbold.Pushed = True Then AddFontStyle (rtbox, FontStyle.Bold) Else RemoveFontStyle (rtbox, FontStyle.Bold) End If

Case 1 if tbbi.pushed = True Ten AddFontStyle (RTBOX, FONTSTYLE.IALIC) ELSE RemoveFontStyle (RTBOX, FONTSTYLE.ITALIC) END IF

Case 2 if Tbbu.pushed = True Ten AddFontStyle (RTBOX, FONTSTYLE.UNDERLINE) ELSE RemoveFontStyle (RTBOX, FONTSTYLE.UNDERLINE) END IF

Case 3 colorDialog1.showdialog () RTBOX.FORECOLOR = Colordialog1.color

Case 6 rtbox.SelectionAlignment = HorizontalAlignment.Left tbbmiddle.Pushed = False tbbright.Pushed = False Case 7 rtbox.SelectionAlignment = HorizontalAlignment.Center tbbleft.Pushed = False tbbright.Pushed = False Case 8 rtbox.SelectionAlignment = HorizontalAlignment.Right tbbleft.Pushed = False tbmiddle.pushed = false

End SELECT

End sub '***************************************** Hide status bar function Private Sub mStatusbar_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mStatusbar.Click If mStatusbar.Checked = True Then StatusBar1.Visible = False mStatusbar.Checked = False Else StatusBar1.Visible = True Mstatusbar.checked = true end if End sub '************************************************************* **** 'status Bar Information Private Sub Handleselect (Byval e as system.EventArgs) Handles mstatus bar.select, map.select, mnew.select, mcopy.select, mnew.select, mcut. Select, mEdit.Select, mExit.Select, mFile.Select, mFind.Select, mFindnext.Select, mFont.Select, mHelp.Select, mHelptopics.Select, mOpen.Select, mPagesetup.Select, mPaste.Select, mPrint.Select, MPrintPreview.select, Mreplace.select, msave.select, msaveas.select, mselectall.select, mstatusbar.select, mundo.select, mview.select Dim Strtext As string

If sender is mstatusbar dam, decide if hidden status bar .... "elseif sender is mabout dam" "You will see some of our development group" Elseif Sender is mclear dam "" Clear all content! " Elseif Sender is Mexit Then Strtext = "Exit Program!" Elseif Sender IS MNEW THEN STRTEXT = "New Document, will be saved ..." Elseif Sender is mcopy kilnText = "Copy selected content" elseif sender is mcut the strtext = "Elseif Sender is Medit Ten Strtext =" editing menu "elseif sender is mfile dam" ELSEIF sender is mfind dam = "display lookup panel .." elseif sender is mfindnext dam "Elseif Sender is mfindnext the Strtext = "Find the next" elseif sender is mfont dam "elseif sender is mopen dam" Open menu "elseif sender is medit the strtext =" editing menu "elseif sender is mpagesetup dam · Strtext =" Page Setup Options Elseif sender is medit dam1xt = "Edit menu" '.........' ........ '........ Else Strtext = String.empty End IF

Writetostatusbar (Strtext) End Sub

Public Sub Writetostatusbar (Byval Text As String) Statusbar1.Text = Text End Sub

Private Sub MenuItem2_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click ColorDialog1.ShowDialog () rtbox.ForeColor = ColorDialog1.Color End Sub '************* *********************************************************** ************************ Bill below is about implementing the Find Function DIM MyPOS AS Integer 'First Declared a Global Variable Private Sub Findtext 'Creating a FindText Function DIM POS AS Integer Dim Target AS String' Get User Enter String Target = TxtBox.Text Pos = INSTBOX.TBOX.TEXT POS = INSTR (Start, RTBox.Text, Target) if Pos> 0 TEN 'found MYPOS = POS RTBOX.SeLectionStart = MyPOS - 1' Highlight RTBOX.SelectionLength = LEN (TXTBOX.TEXT) RTBOX.FOCUS () Else Msgbox ("Didn't find!")

End if End Sub

Private sub find_click (byvalgend, byval e as system.eventargs) Handles Find.click FindText (1) End Sub

Private sub findnext_click (Byval E AS System.EventArgs) Handles Findnext.Click FindText (MyPOS 1) End Sub

Private sub Button4_Click (Byval e as system.EventArgs) Handles ClosePanel.Click Panel1.visible = false end sub

'********************************************************** *********************************************************** ********* 'The following program uses DIM Dragging as Boolean Dim Mousex as INTEGER DIM MOUSEDOWN (Byval E AS Object, Byval E AS ISTEM .Windows.Forms.MouseEventArgs) Handles Panel1.MouseDown If e.Button = MouseButtons.Left Then dragging = True mousex = -eX mousey = -eY Dim clipleft As Integer = Me.PointToClient (MousePosition) .X - Panel1.Location.X Dim cliptop As Integer = Me.PointToClient (MousePosition) .Y - Panel1.Location.Y Dim clipwidth As Integer = Me.ClientSize.Width - (Panel1.Width - clipleft) Dim clipheight As Integer = Me.ClientSize.Height - (Panel1 .Height - cliptop) Cursor.Clip = Me.Rectangletoscreen (New Rectangle (Clipleft, Clipw, Clipwidth, ClipHeight) Panel1.invalidate () endiffate () End if End Subprivate Sub Panel1_mousem ove (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseMove If dragging Then 'control moves to a new location Dim MPosition As New Point () MPosition = Me.PointToClient (MousePosition) MPosition.Offset (mousex, mousey) 'Do not leave the main window Panel1.Location = MPSITION End if End Sub

Private Sub panel1_MouseUp (ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Panel1.MouseUp If dragging Then 'end of the drag dragging = False Cursor.Clip = Nothing Panel1.Invalidate () End If End Sub' * *********************************************************** *********************************************************** *********** Private Sub Replace_Click (Byval E AS System.EventArgs) Handles Mpreplace.click RTBOX.TEXT = RTBOX.TEXT.REPLACE (TXTBOX.TEXT, RPBOX.TEXT ) End Sub

Private sub mfind_click (byval sender as system.Object, byval e as system.eventargs) Handles mfind.click parad1.visible = true

End Sub

Private sub mfindnext_click (byvalgend, byval e as system.eventargs) Handles Mfindnext.Click Findtext (MyPOS 1) End Sub

Private Sub mReplace_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mReplace.Click rtbox.Text = rtbox.Text.Replace (txtbox.Text, rpbox.Text) End SubEnd Class

'Finish.

转载请注明原文地址:https://www.9cbs.com/read-3738.html

New Post(0)