Previously, I only knew that RichTextBox is a multi-line text box and can be used as a text field. However, we do not know that RichTextBox can be used for functions similar to Windows WordPad and word processing.
1) RichTextBox implements document management (as shown in)
In this program, the key function is to create, open, and save a document. The area of the displayed document is a RichTextBox Control, which is described one by one below.
The new document function is to open a new window and specify the parent window.
Frm2 F2 = new frm2 (); <br/> f2.mdiparent = This; <br/> f2.show ();
Enable the document function: select and open the document and load it in the RichTextBox Control of the child form.
Openfiledialog1.filter = "TXT format (*. TXT) | *. TXT | all files | *. * "; <br/> openfiledialog1.title =" open "; <br/> If (openfiledialog1.showdialog () = dialogresult. OK) <br/> {</P> <p> frmchild. TEXT = openfiledialog1.filename; <br/> frmchild. richtextbox1.clear (); <br/> frmchild. richtextbox1. loadFile (openfiledialog1. filename, richtextboxstreamtype. plaintext); <br/> frmchild. mdiparent = This; <br/> frmchild. show (); </P> <p> printdocument1.documentname = openfiledialog1.filename; <br/>}
Saving documents:
Savefiledialog1.filter = "text file (* txt) | *. TXT "; <br/> savefiledialog1.filterindex = 2; <br/> If (savefiledialog1.showdialog () = dialogresult. OK) <br/>{< br/> frmchild. richtextbox1.savefile (savefiledialog1.filename); <br/>}
2) use RichTextBox to find and locate text, as shown in figure
The preceding section does not describe the functions opened. Let's talk about how to implement the query function.
If (textbox1.text! = "") <Br/>{< br/> If (richtextbox1.text. length> 0) <br/>{< br/> If (g_index = richtextbox1.text. indexof (textbox1.text, g_index) =-1) <br/>{< br/> MessageBox. show ("no results found"); <br/> g_index = 0; <br/>}< br/> else <br/>{< br/> richtextbox1.select (g_index, textbox1.text. length); <br/> richtextbox1.selectioncolor = color. purple; <br/> g_index = g_index + textbox1.text. length; <br/>}< br/> else <br/>{< br/> MessageBox. show ("Enter query conditions"); <br/>}< br/>}
3) insert an image into RichTextBox as follows:
Function Description of inserting an image:
Openfiledialog1.filter = "BMP file (*. BMP) | *. BMP | JPG file (*. JPG) | *. JPG | ICO file (*. ICO) | *. ICO "; <br/> openfiledialog1.title =" open image "; <br/> openfiledialog1.filterindex = 2; <br/> If (openfiledialog1.showdialog () = dialogresult. OK) <br/>{< br/> bitmap BMP = new Bitmap (openfiledialog1.filename); <br/> clipboard. setdataobject (BMP, false); <br/> If (richtextbox1.canpaste (dataformats. getformat (dataformats. bitmap) <br/> richtextbox1.paste (); <br/>}
Imagine if we integrate all the above functions, beautify the interface, and improve and process the relevant functions, so is a word processing software that can be used as a word processing tool!
A good thinking model can bring more, better, and more novel experiences to your program.