C # experiment inspiration for WPF

Source: Internet
Author: User

Experimental procedure: ToDoList

This blog mainly records the development process of experimental procedures.

1  Public voidSave ()2         {3System.Text.StringBuilder report =NewSystem.Text.StringBuilder ();4             foreach(Task ToDoIteminchtaskList)5             {6Report. Append (toDoItem.TaskTitle.ToString () +"\ t"+ toDoItem.TaskDescription.ToString () +"\ t"+ toDoItem.TaskDueDate.ToString () +"\ t"+ toDoItem.TaskPriority.ToString () +"\ t"+ toDoItem.CreationDate.ToString () +"\ t"+ toDoItem.IsTaskComplete.ToString () +"\ n");7             }8 9Microsoft.Win32.SaveFileDialog dlg =NewMicrosoft.Win32.SaveFileDialog ();TenDlg. FileName ="ToDoList";//Default file name OneDlg. DEFAULTEXT =". txt";//Default File extension ADlg. Filter ="Text documents (. txt) |*.txt";//Filter files by extension -  -             //Show Save File dialog box thenullable<BOOL> result =dlg. ShowDialog (); -  -             //Process Save File dialog box results -             if(Result = =true) +             { -                 //Save Document + File.writealltext (dlg. FileName, report. ToString ()); A             } at}//End Save ()

The above code is mainly implemented to save the data in TXT format, there is a local file.

 Public voidLoad () {tasklist.clear (); Microsoft.Win32.OpenFileDialog Dlg=NewMicrosoft.Win32.OpenFileDialog (); Dlg. FileName="ToDoList";//Default file nameDlg. DEFAULTEXT =". txt";//Default File extensionDlg. Filter ="Text documents (. txt) |*.txt";//Filter files by extension//Show Open File dialog boxnullable<BOOL> result =dlg.            ShowDialog (); //Process Open File dialog box results            if(Result = =true)            {                //Open DocumentSystem.IO.StreamReader MyFile =NewSystem.IO.StreamReader (@dlg.                FileName); intLineCount =0; using(varReader =File.OpenText (@dlg. FileName) { while(Reader. ReadLine ()! =NULL) {LineCount++; }                }                 for(inti =1; I <= LineCount; i++)                {                    stringMyString =Myfile.readline (); string[] obj = Mystring.split ('\ t'); Tasklist.add (NewTask {tasktitle = obj[0]. ToString (), taskdescription = obj[1]. ToString (), taskduedate = obj[2]. ToString (), taskpriority = obj[3]. ToString (), CreationDate = obj[4], Istaskcomplete = Convert.toboolean (obj[5]) }); }//End for Loop            }//END Statement        } //End public bool Load ()

corresponding to the local data that is bound to it from the program.

The front interface is designed as follows

Where the button code for the capture event is as follows

1  Private voidAddtask_click (Objectsender, RoutedEventArgs e)2         {3             if(!tasktitletextbox.text.equals (string. Empty) &&!descriptiontextbox.text.equals (string. Empty) &&!datefield.text.equals (string. Empty) &&!prioritydropbox.text.equals (string. Empty))4             {5 Todo.additem (Tasktitletextbox.text, Descriptiontextbox.text, Datefield.text, prioritydropbox.text); 6 ToDoListView.Items.Refresh ();7 changeuistate (uistate.addstate);8isprogramsaved =false;9             }Ten             Else One             { AMessageBox.Show ("Make sure all fields is filled in!","Error", Messageboxbutton.ok, messageboximage.error); -             } -}

This includes filling decisions for task time priority topics and descriptions

Add the data to the text if all is filled in if any of the items are not filled in, the error is returned.

In contrast, the foreground interface design is slightly simpler than the background program development.

C # experiment inspiration for WPF

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.