By accident, I insisted on making the software. If you are interested in technical details and their applications, this topic will not disappoint you. A commercial applicationProgramAll the required features are available. The following describes the winforms data binding technology.CodeConcise and elegant.
See the settings form of Data Loader. The interface effect is shown in.
This form stores the Data Loader settings. Downloaded path is the path for saving the downloaded document. When downloaded the blog document, it will check whether the downloaded document exists here. If yes, skip the download; connection string is the connection string to correctly connect to the Document Server. Failed cleanup file is used to load the document to the server. If it is not in the RTF format, you need to consider converting the format, the intermediate file to be converted is not required. After the file is imported to the database, it must be cleared. If the file is not cleared successfully, the process may be occupied and saved here, in order to clean it at the right time. The PDF watch path is the path for saving the PDF watch, which is used to monitor the path of the PDF change to provide the conversion and import service; auto Import after download complete indicates whether to start the import program after the download is complete; Start application when computer starts indicates to add the start plane and start automatically when the machine is started.
Let's take a look at its code implementation to understand the data binding technology.
Drag a bindingsource control to the form, set its data source to object, and point to the settingentity object. As shown in, data is bound to the download path and its text attribute is bound to the downloadedpath attribute of the data source. This is also true for other attributes.
Write the following code in the form Loading Code:
settingmanager Mgr = New settingmanager (); private void settingoption_load ( Object sender, eventargs e) { try {settingentity setting = Mgr. getsetting (); settingbindingsource. datasource = setting;} catch {}
In the close code of the form, write and save the Code as follows:
private void settingoption_formclosing ( Object sender, formclosingeventargs e) { try {settingentity setting = settingbindingsource. datasource as settingentity; Mgr. savesetting (setting) ;}< SPAN class = "kwrd"> catch {}
All right, this is all the program code. With this technology, you can save a lot of code for applications. Back to the previous program design, it is usually written in this way.
Private VoidSettingoption_load (ObjectSender, eventargs e ){Try{Settingentity setting = Mgr. getsetting (); txtdownloadedpath. Text = Setting. downloadedpath ;}Catch{}}
As you can see, you need to manually bind the property to the text editing control. Similarly, when closing the form, you also need to write such code.
Private VoidSettingoption_formclosing (ObjectSender, formclosingeventargs e ){Try{Settingentity setting = Mgr. getsetting (); setting. downloadedpath = txtdownloadedpath. Text ;}Catch{}
}
This is just a control. If there are dozens of widgets, the same code needs to be written many times. However, if you use winforms's built-in data binding technology, the situation will be greatly improved, which can save a lot of unnecessary code and facilitate maintenance.