Книга: C# 2008 Programmer
Coding the Application
Coding the Application
Now to code the application. Switching to the code-behind of Form1
, import the following namespaces:
using System.Net;
using System.IO;
Define the WebRequestMethod
enumeration:
namespace PhotoViewer {
enum WebRequestMethod {
MakeDirectory,
DownloadFile,
ListDirectoryDetails,
RemoveDirectory,
DeleteFile
}
Declare the following constants and member variables:
public partial class Form1 : Form {
//---constants for the icon images---
const int ico_OPEN = 0;
const int ico_CLOSE = 1;
const int ico_PHOTO = 2;
In Form1
, select the three TextBox
controls (you can Ctrl+click each of them) that ask for the FTP server name, user name, and password (see Figure 16-9). In the Properties window, double-click the Leave
property to generate an event handler stub for the Leave
event.
Figure 16-9
Visual Studio 2008 then generates the txtFtpServer_Leave
event handler:
private void txtFTPServer_Leave(object sender, EventArgs e) {
}
The event handler is invoked whenever the focus leaves one of the three TextBox
controls you have selected. This is where you can save the information entered by the user into the application settings you have created in the previous section.
Code the event handler as follows:
private void txtFTPServer_Leave(object sender, EventArgs e) {
//---save the values in the textbox controls
// into the application settings---
Properties.Settings.Default.FTP_SERVER = txtFTPServer.Text;
Properties.Settings.Default.UserName = txtUserName.Text;
Properties.Settings.Default.Password = txtPassword.Text;
Properties.Settings.Default.Save();
}
You access the various application settings using the Properties.Settings.Default
class (as generated in the Settings.Designer.cs
file). Once the application settings are assigned a value, you need to persist them using the Save()
method.
- Testing the Program
- The Project
- Creating the Application
- The Controls
- Testing the Application
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Appendix E. Other resources and links
- Example NAT machine in theory
- The final stage of our NAT machine
- Compiling the user-land applications