In the previous article, the CRC.exe that generated the output will become the built-in module for this form application.
Create a new Windows Forms application called Crclick. Locate the application CRC.exe from the console application and copy it to the Debuge folder in the Crclick folder. There are also Test.txt for testing.
Open the Form design page, insert two textbox and a button, the length textbox is used to display the absolute path of the verified file, and the short textbox displays the final check code. button to fire the selected file window. The design is as follows:
For the trigger event of a button, we generate a OpenFileDialog control, which is used to read and open the file. The specific code is as follows: File Form.cs
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Diagnostics;6 usingSystem.Drawing;7 usingSystem.IO;8 usingSystem.Linq;9 usingSystem.Text;Ten usingSystem.Threading.Tasks; One usingSystem.Windows.Forms; A - namespaceCrclick - { the Public Partial classCrclick:form - { - PublicCrclick () - { + InitializeComponent (); - } + A Private voidButton1_Click (Objectsender, EventArgs e) at { -Stream MyStream =NULL; -OpenFileDialog OpenFileDialog1 =NewOpenFileDialog (); -Openfiledialog1.initialdirectory =@".. \.. \.. \crclick\crclick\bin\debug"; -Openfiledialog1.filter ="txt files (*.txt) |*.txt| All Files (*. *) |*.*"; -Openfiledialog1.filterindex =2 ; inOpenfiledialog1.restoredirectory =true ; - to if(Openfiledialog1.showdialog () = =DialogResult.OK) + { - Try the { * if((MyStream = Openfiledialog1.openfile ())! =NULL) $ {Panax Notoginseng using(MyStream) - { theRoute. Text =Openfiledialog1.filename; + AProcess Pro =NewProcess (); thePro. Startinfo.filename ="CRC.exe"; +Pro. Startinfo.useshellexecute =false; -Pro. Startinfo.arguments =route. Text; $Pro. Startinfo.redirectstandardoutput =true; $Pro. Startinfo.redirectstandardinput =true; - Pro. Start (); -Crcresult.text =Pro. Standardoutput.readtoend (); the - }Wuyi } the } - Catch(Exception ex) Wu { -MessageBox.Show ("error:could not read file from disk. Original Error:"+Ex. Message); About } $ } - } - } -}
from 39 to 49 lines, when the file selection is finished, click "Open" after the trigger event, the absolute path of the file is displayed in the Long text box, while calling the process CRC.exe operation, the results are output in a short box ,
The result is
So, a CRC calibration program is complete!
Need source code and source files can leave a message (^>^)
CRC Check Program 3: Open TXT file via form program get data source, byte-by-bit CRC check