Form Move API: Reference namespace required
//Form Mobile API[DllImport ("user32.dll")] Public Static extern BOOLreleasecapture (); [DllImport ("user32.dll")] Public Static extern BOOLSendMessage (INTPTR hwnd,intWmsg,intWParam,intiparam); Public Const intWm_syscommand =0x0112; Public Const intSc_move =0xf010; Public Const intHtcaption =0x0002; [DllImport ("User32")]Private Static extern intSendMessage (INTPTR hwnd,intWmsg,intWParam, IntPtr lParam);Private Const intWm_setredraw =0xB;Private voidForm1_mousedown (Objectsender, MouseEventArgs e) { if( This. WindowState = =formwindowstate.normal) {releasecapture (); SendMessage ( This. Handle, Wm_syscommand, Sc_move + htcaption,0); }}
Form Shadow API: Add a sentence to the constructor
//form Shadow API Const intCs_dropshadow =0x20000; Const intGcl_style = (- -); [DllImport ("user32.dll", CharSet =CharSet.Auto)] Public Static extern intSetclasslong (INTPTR hwnd,intNIndex,intDwnewlong); [DllImport ("user32.dll", CharSet =CharSet.Auto)] Public Static extern intGetclasslong (INTPTR hwnd,intNIndex); PublicForm1 () {InitializeComponent (); Setclasslong ( This. Handle, Gcl_style, Getclasslong ( This. Handle, Gcl_style) |Cs_dropshadow); }
1.colordialog: Color dialog box changes the font Color of the dialog box
Private void Custom Ctoolstripmenuitem_click (object sender, EventArgs e) { = Colordialog1.showdialog (); if (dr = = DialogResult.OK) { = colordialog1.color; } }
2.fontdialog: Font dialog box
Private void option Otoolstripmenuitem_click (object sender, EventArgs e) { = Fontdialog1.showdialog (); if (dr = = DialogResult.OK) { = fontdialog1.font; } }
Showapply: Whether the Apply button is displayed
Showcolor: Whether the color button is displayed
To set the font color, add in if:
Richtextbox.forecolor=fontdialog.color;
3.folderbrowserdialog: File path
Private void button2_click (object sender, EventArgs e) { DialogResult dr= Folderbrowserdialog1.showdialog (); if (dr = = DialogResult.OK) { = folderbrowserdialog1.selectedpath; } }
4.openfiledialog: Open File
Use a stream to apply a namespace:
using System.IO;
Private voidButton2_Click (Objectsender, EventArgs e) {Openfiledialog1.filter="text Files |*.txt";//Set Open FormatDialogResult dr=Openfiledialog1.showdialog (); if(dr = =DialogResult.OK) {Label1. Text= Openfiledialog1.filename;//Show file path nameStreamReader sr =NewStreamReader (Openfiledialog1.filename,encoding.default);//Prevent garbled charactersrichtextbox1.text=Sr. ReadToEnd (); } }
5.savefiledialog: Save File
Private voidButton3_Click (Objectsender, EventArgs e) {Savefiledialog1.filter="text Files |*.txt|word|*.doc"; DialogResult Dr=Savefiledialog1.showdialog (); if(dr = =DialogResult.OK) {StreamWriter SW=NewStreamWriter (Savefiledialog1.filename,false, Encoding.default);//Prevent garbled charactersSW. Write (richTextBox1.Text); Sw. Flush (); } }
Form move and Shadow, dialog box controls