Книга: 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 {

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;

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. 

Оглавление книги

Генерация: 0.976. Запросов К БД/Cache: 3 / 0
Вверх Вниз