Form move and Shadow, dialog box controls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.