1, the MDI form is equipped with two forms frmmain, frmChild, then: frmmain: Set the ismdicontainer property to True Open Subside: Write the following code in related events: frmChild child = new fmChild (); child.mdiparent = this; // This means that the form is a parent form Child.show (); when a child form is opened, if only one sub-form is allowed, it can be judged: if (this.activemdichild! = null) {THIS .Activemdichild.close (); // Close the open subsidy // ....} Change the MDI main form background first declare a form object private system.windows.forms.mdiclient m_mdiclient; in Form_Load and other incidents Add the following code: int icnt = this.controls.count; for (int i = 0; i 2. Create a system tray menu 2.1, create a contextMenu menu 2.2, add a Notifyicon component, set the ContextMenu property as cmnmain 2.3, change event (minimize the event, etc.) private void frmmain_sizechanged (Object sender, Eventargs e) { IF (this.windowstate == formwindowstate.minimized) {this.hide (); noimain.visible = true;}} 2.4, the corresponding user clicks the system tray on the ContextMenu menu event private void mniopen (Object sender, Eventargs e) {noimain.visible = false; this.show (); this.focus (); 2.5, Response User Double-click System Tray Icon Event Private Void NoImain_doubleClick (Object S, Eventargs E) {Minopen.PerformClick (); // Quite Click Events with the Mniopen button} ** Note Add appropriate event handle ** 3. Create an irregular form 3.1, create an irregular image on the form, you can draw it with GDI , or use the image to populate 3.2 on the image control, set the form of BackColor as Colora, and then set TransparenchKey to Colora 3.3. , Set Formborderstyle to none; 4, create top form this.topmost = true; // Set the topmost of the form to TRUE 5, call external programs Using system.diagnostics Process proc = new process (); proc.startinfo.filename = @ "notepad.exe"; // Note path proc.startinfo.arguments = ""; proc.start (); // Get the current directory Directory.getCurrentDirectory () (use system.io) 6. Toolbar's use Toolbar control usually requires an ImageList control combined with (you need to use it) response Toolbar Click Event Procedure Code: Switch (Toolbarname.Buttons.indexof (E.Button) {cas 0: // First Buttons // Code ... Break; Case 1: // Second button // code ... Break; // Other Case code default: // Default processing, but all items are not compliant // CODE ... Break; 7. Pop-up dialog Get the relevant return value running the following code in the form of the form, you can ask DialogResult result = messagebox.show when the user closes the form, really want to turn off the window? "," Close Tips ", MessageBoxButtons.Question; if (result == DialogResult.ok) {// Close window E.cancel = false;} else {// Cancellation E.CANCEL = true; 8. Print control requires two controls PrintDocument PrintPreviewDialog: Preview dialog boxes, you need PrintDocument to use, set the document attribute to the corresponding PrintDocument PrintDocument PRINTPAGE Event (Print or Preview Event Handler) code, must. Float float float fltlineperpage = 0; long linemargin = E.Marginbounds.top; int int4t = 0; string strline; // Calculate the number of rows that can be accommodated per page to determine when floring fltlineperpage = E.Marginbounds.Height / TxtPrintText.Font.getHEight (E.Graphics); while (((strLine = StreamToPrint.ReadLine ()) = null) && (intCount / / Decide whether to change the page if (strline! = Null) {E.hasmorepages = true;} else {e.hasmorepages = false;} STREAMTOPRINT of the above code needs to be declared as a window-level variable: private system.io.StringReader streamtoprint Open the preview dialog code (do not write in the PrintPage event) streamtoprint = new system.io.stringReader (txtprinttext.text); printpreviewDialogname.showdialog (); 9, String object essence and StringBuilder class, string uses String objects that are unable to change, when we modify a String object, it will generate a new String object, so it is recommended to use StringBuilder when you need to change the character object. Class: [Sample Code] Constructs a query string StringBuilder SB = new stringbuilder (""); sb.append ("select * from employees where"); sb.append ("id = {0} and"); SB. Append ("Title = '{1}'"); string cmd = sb.toString (); SB = NULL; // Clear it when it is no longer needed CMD = String.Format (cmd, txtid.text, txttile.text); // fill the format item with the actual value The determination string is empty: Check if a string is empty or not a basic programming requirement, an effective way is to use NULL or "" comparison. Comparison string: Use string.equals method to compare two strings string str1 = "youRText"; if (str1.equals ("teststing") {// do something} 10. It is determined whether a string needs to be used in another string (array) String.Split (char); / / Split according to char, return to the array.indexof (Array, String) : Returns the subscript of the first matching item specified in Array: Returns the subscript of the last matching item of the String in Array If there is no match, return -1 [ Sample code]: String Strnum = "001,003,005,008"; string [] strartray = strnum.split (','); // Press comma split, split characters as Char or Char array console.writeline (Array.indexof (Strarray, "004"). TOSTRING ()); 11. DataGrid and list mappings are binded from the database to DataGrid, the DataGrid's column header is usually the same as the field name of the database. If you don't want this, you can use the map and column mapping technology: use system .DATA.COMMON; String strsql = "select * from department"; OLEDBDataAdapter Adapter = New OLEDBDataAdapter (strsql, conn); DataTableMapping DTMDEP = adapter.tablemappings.add ("Department", "Department Table"); DTMDEP.COLUMNMAPPINGS.ADD ("DEP_ID", "Department Number"); DTMDEP.COLUMNMAPPINGS.ADD ("Dep_name", "Department Name"); Dataset DS = New Dataset (); Adapter.Fill (DS, "Department"); // Can't use "department table" here Response Click Event (DataGrid's CurrentCellchange DataGridName.currentcell.columnname.currentcell.columnnumber; // Click the subscript, starting from 0, the next DataGridName.currentcell.rownumber; // Single Run Data DataGridName [datagridname .Currentcell]; // 所 单 行行 and column value DataGridName [datagridname.currentrowindex, n] .tostring (); // Get the value of the Northern N 1 column 12. Dynamically add a menu and add a top menu to it: mainmenuname.MenuItems.Add ("Top Menu One"); / / Each additional automatic row Add submenu: MenuItem mniItemN = new MenuItem ( "MenuItemText") MenuItem mniItemN = new MenuItem ( "MenuItemText", new EventHandler (EventDealName)) MainMenuName.MenuItems [n] .MenuItems.Add (mniItemN); // n is to be Added top menu subscript, starting from 0 Add events after creating a menu: mniitemn.click = new eventhandler (eventdealname); You can also add events while adding a menu: MenuItem mniitemn = new menuItem ("MenuItemText", New EventDealName); mainmenuname.menuitems [n] .menuitems.Add (mniitemn); 13. Regular expressions simple applications (match, replace, split) Using system.text.regularexpressions; // Matching example string strregextext = "Your number is: 020-32234102"; string filter = @ "/ d {3} - / d *"; Regex regex = new regex; match match = regex.match (strregextext); If (match.success) // determines if there is a match {Console.WriteLine ("length:" match.length.tostring ()); console.writeline ("string of matching:" match. TOSTRING ()); console.writeline ("Match item is subscript in the original string:" Match.index.toString ());} // Replacement example string replacedText = regex.replace (strregextext, "020-88888888"); console.writeline (replacedText); // Output "Your number is: 020-88888888" / / Split STRING STRSPLITTEXT = "A 020-32654 has 020-35648 020-365984"; Foreach (String s in regex.split (strsplittext)) {console.writeline (s); // Output "A-B }} 13, multi-thread simple programming Using system.threading; Thread ThreadTest = new Thread (new ThreadStart (ThreadCompute)); ThreadTest.Start (); // Run method using ThreadCompute ThreadCompute method Prototype another thread: private void ThreadCompute () {} 14, the registry operation using System.Diagnostics; using Microsoft.win32; // Operating Registry RegistryKey Regkey = registry.localmachine.Opensubkey ("Software", True; // Add a subkey and add key value to registryKey newkey = regkey.createSubkey ("regnewkey"); newkey.setValue ("keyname1", "keyvalue1"); newkey.setValue ("keyname2", "keyvalue2") ; / / Get newly added value messagebox.show (newkey.getvalue ("keyname1"). TOSTRING ()); / / Delete a key value (pair) newkey.deletevalue ("keyname1"); // Delete the entire subkey regkey.deleteSubKey ("RegneWKey");