C # Common Instances

Source: Internet
Author: User
Tags time and date

1 hours

1.1 shows the time of the walk

Control: The textbox is displayed as a date, named Txtdatetimer

The timer is named time for the clock

Private void Dtdatetimer_tick (object sender, EventArgs e)        {            DateTime dt = DateTime.Now;            Txtdatetimer.text = dt. ToString ();     }

Design the screen to perform the painting surface

1.2 Time and date of access to the machine

Control: Label to display the time and date of the control, named: Lbldatetime

RadioButton controls, which are chosen to display time and date controls, are named Showdate and Showtime

button to display the time Date button, named Btnshow

Private void Btnshow_click (object sender, EventArgs e)        {            if (showdate.checked)                Lbldatetime.text = DateTime.Now.Year + " year " + DateTime.Now.Month + " month " + DateTime.Now.Day + " Day ";            if (showtime.checked)                lbldatetime.text = DateTime.Now.Hour + " hour " + DateTime.Now.Minute + " min " + DateTime.Now.Second + " sec ";        }

Design the screen to perform the painting surface

1.3 Comparison of the size and calculation of the number of days

Control: The button is named BTNBJ for the comparison date button

DateTimePicker to show the dates chosen, named Dtpks and Dtpjs

Label to display the text

Private voidBtnbj_click (Objectsender, EventArgs e) {stringStrone = Dtpone.text;stringStrtwo = Dtptwo.text;            DateTime Dtone = Convert.todatetime (Strone); DateTime dttwo = Convert.todatetime (strtwo);if(Datetime.compare (Dtone, Dttwo) > 0) {Txttime.text = "Comparison Date:"+ Strone +"VS"+ Strtwo +"\ r \ n" + "comparison results:"+ Strone +">"+ Strtwo +"\ r \ n" + "difference in days:"; }Else if(Datetime.compare (Dtone, Dttwo) < 0) {Txttime.text = "Comparison Date:"+ Strone +"VS"+ Strtwo +"\ r \ n" + "comparison results:"+ Strone +"<"+ Strtwo +"\ r \ n" + "difference in days:"; }Else if(Datetime.compare (Dtone, dttwo) = = 0) {Txttime.text = "Comparison Date:"+ Strone +"VS"+ Strtwo +"\ r \ n" + "comparison results:"+ Strone +"="+ Strtwo +"\ r \ n" + "difference in days:"; } TimeSpan ts = Dttwo-dtone;//Calculate the number of daysTxttime.text + = ts. Days.tostring () + "days" + "\ r \ n"; }

Design the screen to perform the painting surface

2 File Folder:

Add named space: Using System.IO;

2.1 Creating folders and deleting folders and numbers

CONTROLS: button to create and delete buttons, named Btncreate,btndelete, as buttons

The textbox is the text, and the number of names, named Txtnumber and Txtname

Label to display the text

Private voidBtncreate_click (Objectsender, EventArgs e) {if(Txtnumber.text = = "" | | txtName.Text = = "") {MessageBox.Show ("Please enter the number and name of the created folder");return; }intnumble = Convert.ToInt32 (Txtnumber.text); for(inti = 1; I <= numble; i++) {directory.createdirectory ("e:\\temp\\"+ txtName.Text + i.tostring ());//Create a folder under the E-tray temp} MessageBox.Show ("Creative Success! "); }Private voidBtndelete_click (Objectsender, EventArgs e) {if(Txtnumber.text = = "" | | txtName.Text = = "") {MessageBox.Show ("Please enter the number of Delete folder");return; }intj = Convert.ToInt32 (Txtnumber.text); for(inti = 1; I <= J; i++) {Directory.delete ("e:\\temp\\"+ txtName.Text + i.tostring ());//Delete language, create a folder under the E-tray temp} MessageBox.Show ("Erase Complete");}

Design the screen to perform the painting surface

2.2 Access to file path:

Control: button to obtain the path button named Btnpath

The textbox is displayed as the file address, named Txtshow

Private void Btnpath_click (object sender, EventArgs e)        {            new FolderBrowserDialog ();            Fbd. ShowDialog ();            Txtshow.text = FBD. SelectedPath;        }

Design the screen to perform the painting surface

3 text

3.1 Create and delete text "zqy text" in "E"

CONTROLS: button to create and delete buttons, named Btn_create,btn_delete, as buttons

Private voidBtn_create_click (Objectsender, EventArgs e) {if(! File.exists ("E:\\zqy.txt")) {FileStream FS1 =NewFileStream ("E:\\zqy.txt", FileMode.Create, FileAccess.Write);//FS1.                Close (); MessageBox.Show ("E:\\zqy.txt" + "text" + "Creating Success", "Tips"); }ElseMessageBox.Show ("E:\\zqy.txt" + "text already exists!", "Tips"); }Private voidBtn_delete_click (Objectsender, EventArgs e) {if(File.exists ("E:\\zqy.txt")) {FileInfo FI =NewFileInfo ("E:\\zqy.txt"); FI.                Delete (); MessageBox.Show ("E:\\zqy.txt" + "text" + "Erase Success", "Tips"); }ElseMessageBox.Show ("E:\\zqy.txt" + "text does not exist!", "Tips");}

Design the screen to perform the painting surface

3.2 Duplicate and paste

CONTROLS: button for copy, Sticky button, named Btncopy and Btnpaste

TextBox for copy, sticky text, named Txtcopy and Txtpaste

Private void Btncopy_click (object sender, EventArgs e)        {            clipboard.setdataobject (txtcopy.text);        }        privatevoid Btnpaste_click (object sender, EventArgs e)        {            IDataObject iData = Clipboard.getdataobject ();            if (Txtcopy.text! = "")            {                txtpaste. Text + = (String) idata.getdata (dataformats.text) + "\ r \ n";            }            Else  MessageBox.Show ("No duplicate text to paste ", " hint ");}

Design the screen to perform the painting surface

C # Common Instances

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.