□ Uses a web browser to view the content of a post

Building the User Interface

To get started, launch Visual Studio 2008 and create a new Windows Mobile 6 Standard application using .NET CF 3.5. Name the application RSSReader.

Don't forget to download the free Windows Mobile 6 Standard SDK (http://microsoft.com/downloads). You need it to create the application detailed in this chapter.

The default Form1 uses the standard form factor of 176×180 pixels. As this application is targeted at users with wide-screen devices, change the FormFactor property of Form1 to Windows Mobile 6 Landscape QVGA.

Populate the default Form1 with the following controls (see also Figure 18-8):

□ One TreeView control

□ Four MenuItem controls

Figure 18-8

Add an ImageList control to Form1 and add three images to its Images property (see Figure 18-9).

Figure 18-9

You can download the images from this book's source code at its Wrox web site.

These images will be used by the TreeView control to display its content when the tree is expanded or closed. Hence, associate the ImageList control to the TreeView control by setting the ImageList property of the TreeView control to ImageList1.

Add a new Windows Form to the project, and populate it with a WebBrowser and MenuItem control (see Figure 18-10). The WebBrowser control will be used to view the content of a posting.

Figure 18-10

Set the Modifiers property of the WebBrowser control to Internal so that the control is accessible from other forms. Specifically, you want to set the content of the control from within Form1.

Switch to the code behind of Form1, and import the following namespaces:

using System.IO;

using System.Net;

using System.Xml;

using System.Text.RegularExpressions;

Declare the following constants and variable:

namespace RSSReader {

 public partial class Form1 : Form {

  //---constants for icons---

  const int ICO_OPEN = 0;

  const int ICO_CLOSE = 1;

  const int ICO_POST = 2;

  //---file containing the list of subscribed feeds---

  string feedsList = @'Feeds.txt';

  //---app's current path---

  string appPath = string.Empty;

  //---the last URL entered (subscribe)---

  string lastURLEntered = string.Empty;

  //---used for displaying a wait message panel---

  Panel displayPanel;

  //---for displaying individual post---

  Form2 frm2 = new Form2();

Creating the Helper Methods

When RSS feeds are being downloaded, you want to display a message on the screen to notify the user that the application is downloading the feed (see Figure 18-11).

Figure 18-11

For this purpose, you can improvise with the aid of the Panel and Label controls. Define the CreatePanel() function so that you can dynamically create the message panel using a couple of Panel controls and a Label control:

//---create a Panel control to display a message---

private Panel CreatePanel(string str) {

 //---background panel---

 Panel panel1 = new Panel() {

  BackColor = Color.Black,

  Location = new Point(52, 13),

  Size = new Size(219, 67),

  Visible = false,

 };

 panel1.BringToFront();

 //---foreground panel---

 Panel panel2 = new Panel() {

  BackColor = Color.LightYellow,

  Location = new Point(3, 3),

  Size = new Size(panel1.Size.Width - 6, panel1.Size.Height - 6)

 };

 //---add the label to display text---

 Label label = new Label() {

  Font = new Font(FontFamily.GenericSansSerif, 12, FontStyle.Bold),

  TextAlign = ContentAlignment.TopCenter,

  Location = new Point(3, 3),

  Size = new Size(panel2.Size.Width - 6, panel2.Size.Height - 6),

  Text = str

 };

 //---adds the label to Panel2---

 panel2.Controls.Add(label);

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату