⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.cs

📁 this is a good book for the visual c#
💻 CS
📖 第 1 页 / 共 2 页
字号:
// Fig. 21.22: Client.cs
// Class that displays weather information that it receives
// from a Web service.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;

namespace TemperatureClient
{
   public class Client : System.Windows.Forms.Form
   {
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label3;
      private System.Windows.Forms.Label label4;
      private System.Windows.Forms.Label label5;
      private System.Windows.Forms.Label label6;
      private System.Windows.Forms.Label label7;
      private System.Windows.Forms.Label label8;
      private System.Windows.Forms.Label label9;
      private System.Windows.Forms.Label label10;
      private System.Windows.Forms.Label label11;
      private System.Windows.Forms.Label label12;
      private System.Windows.Forms.Label label13;
      private System.Windows.Forms.Label label14;
      private System.Windows.Forms.Label label15;
      private System.Windows.Forms.Label label16;
      private System.Windows.Forms.Label label17;
      private System.Windows.Forms.Label label18;
      private System.Windows.Forms.Label label19;
      private System.Windows.Forms.Label label20;
      private System.Windows.Forms.Label label21;
      private System.Windows.Forms.Label label22;
      private System.Windows.Forms.Label label23;
      private System.Windows.Forms.Label label24;
      private System.Windows.Forms.Label label25;
      private System.Windows.Forms.Label label26;
      private System.Windows.Forms.Label label27;
      private System.Windows.Forms.Label label28;
      private System.Windows.Forms.Label label29;
      private System.Windows.Forms.Label label30;
      private System.Windows.Forms.Label label31;
      private System.Windows.Forms.Label label32;
      private System.Windows.Forms.Label label33;
      private System.Windows.Forms.Label label34;
      private System.Windows.Forms.Label label36;
      private System.Windows.Forms.Label label35;

      private System.ComponentModel.Container components = 
         null;

      public Client()
      {
         InitializeComponent();

         localhost.TemperatureServer client = 
            new localhost.TemperatureServer();
         client.CookieContainer = new CookieContainer();
         client.UpdateWeatherConditions();

         string[] cities = client.Cities();
         string[] descriptions = client.Descriptions();
         string[] temperatures = client.Temperatures();

         label35.BackgroundImage = new Bitmap( 
            "images/header.png" );
         label36.BackgroundImage = new Bitmap( 
            "images/header.png" );
        
         // create Hashtable and populate it with every label
         Hashtable cityLabels = new Hashtable();
         cityLabels.Add( 1, label1 );
         cityLabels.Add( 2, label2 );
         cityLabels.Add( 3, label3 );
         cityLabels.Add( 4, label4 );
         cityLabels.Add( 5, label5 );
         cityLabels.Add( 6, label6 );
         cityLabels.Add( 7, label7 );
         cityLabels.Add( 8, label8 );
         cityLabels.Add( 9, label9 );
         cityLabels.Add( 10, label10 );
         cityLabels.Add( 11, label11 );
         cityLabels.Add( 12, label12 );
         cityLabels.Add( 13, label13 );
         cityLabels.Add( 14, label14 );
         cityLabels.Add( 15, label15 );
         cityLabels.Add( 16, label16 );
         cityLabels.Add( 17, label17 );
         cityLabels.Add( 18, label18 );
         cityLabels.Add( 19, label19 );
         cityLabels.Add( 20, label20 );
         cityLabels.Add( 21, label21 );
         cityLabels.Add( 22, label22 );
         cityLabels.Add( 23, label23 );
         cityLabels.Add( 24, label24 );
         cityLabels.Add( 25, label25 );
         cityLabels.Add( 26, label26 );
         cityLabels.Add( 27, label27 );
         cityLabels.Add( 28, label28 );
         cityLabels.Add( 29, label29 );
         cityLabels.Add( 30, label30 );
         cityLabels.Add( 31, label31 );
         cityLabels.Add( 32, label32 );
         cityLabels.Add( 33, label33 );
         cityLabels.Add( 34, label34 );

         // create Hashtable and populate with 
         // all weather conditions
         Hashtable weather = new Hashtable();
         weather.Add( "SUNNY", "sunny" );
         weather.Add( "PTCLDY", "pcloudy" );
         weather.Add( "CLOUDY", "mcloudy" );
         weather.Add( "MOCLDY", "mcloudy" );
         weather.Add( "TSTRMS", "rain" );
         weather.Add( "RAIN", "rain" );
         weather.Add( "SNOW", "snow" );
         weather.Add( "VRYHOT", "vryhot" );
         weather.Add( "FAIR", "fair" );
         weather.Add( "RNSNOW", "rnsnow" );
         weather.Add( "SHWRS", "showers" );
         weather.Add( "WINDY", "windy" );
         weather.Add( "NOINFO", "noinfo" );
         weather.Add( "MISG", "noinfo" );
         weather.Add( "DRZL", "rain" );
         weather.Add( "HAZE", "noinfo" );
         weather.Add( "SMOKE", "mcloudy" );
         weather.Add( "SNOWSHWRS", "snow" );
         weather.Add( "FLRRYS", "snow" );

         Bitmap background = new Bitmap( "images/back.png" );
         Font font = new Font( "Courier New", 8, 
            FontStyle.Bold );

         // for every city
         for ( int i = 0; i < cities.Length; i++ )
         {
            // use Hashtable cityLabels to find the next Label
            Label currentCity = ( Label )cityLabels[ i + 1 ];

            // set current Label's image to image 
            // corresponding to the city's weather condition - 
            // find correct image name in Hashtable weather
            currentCity.Image = new Bitmap( "images/" + 
               weather[ descriptions[ i ].Trim() ] + ".png" );

            // set background image, font and forecolor 
            // of Label
            currentCity.BackgroundImage = background;
            currentCity.Font = font;
            currentCity.ForeColor = Color.White;

            // set label's text to city name
            currentCity.Text = "\r\n" + cities[ i ] + " " + 
               temperatures[ i ];
         }

      } // end of constructor

		#region Windows Form Designer generated code      
      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      protected override void Dispose( bool disposing )
      {
         if( disposing )
         {
            if(components != null)
            {
               components.Dispose();
            }
         }
         base.Dispose( disposing );
      }
      /// <summary>
      /// Required method for Designer support - do not modify
      /// the contents of this method with the code editor.
      /// </summary>
      private void InitializeComponent()
      {
         this.label8 = new System.Windows.Forms.Label();
         this.label9 = new System.Windows.Forms.Label();
         this.label4 = new System.Windows.Forms.Label();
         this.label5 = new System.Windows.Forms.Label();
         this.label6 = new System.Windows.Forms.Label();
         this.label7 = new System.Windows.Forms.Label();
         this.label1 = new System.Windows.Forms.Label();
         this.label2 = new System.Windows.Forms.Label();
         this.label3 = new System.Windows.Forms.Label();
         this.label10 = new System.Windows.Forms.Label();
         this.label13 = new System.Windows.Forms.Label();
         this.label35 = new System.Windows.Forms.Label();
         this.label28 = new System.Windows.Forms.Label();
         this.label29 = new System.Windows.Forms.Label();
         this.label26 = new System.Windows.Forms.Label();
         this.label27 = new System.Windows.Forms.Label();
         this.label24 = new System.Windows.Forms.Label();
         this.label25 = new System.Windows.Forms.Label();
         this.label22 = new System.Windows.Forms.Label();
         this.label23 = new System.Windows.Forms.Label();
         this.label20 = new System.Windows.Forms.Label();
         this.label21 = new System.Windows.Forms.Label();
         this.label19 = new System.Windows.Forms.Label();
         this.label18 = new System.Windows.Forms.Label();
         this.label15 = new System.Windows.Forms.Label();
         this.label14 = new System.Windows.Forms.Label();
         this.label17 = new System.Windows.Forms.Label();
         this.label16 = new System.Windows.Forms.Label();
         this.label11 = new System.Windows.Forms.Label();
         this.label30 = new System.Windows.Forms.Label();
         this.label36 = new System.Windows.Forms.Label();
         this.label12 = new System.Windows.Forms.Label();
         this.label34 = new System.Windows.Forms.Label();
         this.label33 = new System.Windows.Forms.Label();
         this.label32 = new System.Windows.Forms.Label();
         this.label31 = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // label8
         // 
         this.label8.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label8.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label8.Location = new System.Drawing.Point(320, 160);
         this.label8.Name = "label8";
         this.label8.Size = new System.Drawing.Size(312, 40);
         this.label8.TabIndex = 0;
         // 
         // label9
         // 
         this.label9.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label9.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label9.Location = new System.Drawing.Point(8, 200);
         this.label9.Name = "label9";
         this.label9.Size = new System.Drawing.Size(312, 40);
         this.label9.TabIndex = 0;
         // 
         // label4
         // 
         this.label4.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label4.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label4.Location = new System.Drawing.Point(320, 80);
         this.label4.Name = "label4";
         this.label4.Size = new System.Drawing.Size(312, 40);
         this.label4.TabIndex = 0;
         // 
         // label5
         // 
         this.label5.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label5.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label5.Location = new System.Drawing.Point(8, 120);
         this.label5.Name = "label5";
         this.label5.Size = new System.Drawing.Size(312, 40);
         this.label5.TabIndex = 0;
         // 
         // label6
         // 
         this.label6.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label6.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label6.Location = new System.Drawing.Point(320, 120);
         this.label6.Name = "label6";
         this.label6.Size = new System.Drawing.Size(312, 40);
         this.label6.TabIndex = 0;
         // 
         // label7
         // 
         this.label7.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label7.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label7.Location = new System.Drawing.Point(8, 160);
         this.label7.Name = "label7";
         this.label7.Size = new System.Drawing.Size(312, 40);
         this.label7.TabIndex = 0;
         // 
         // label1
         // 
         this.label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label1.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label1.Location = new System.Drawing.Point(8, 40);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(312, 40);
         this.label1.TabIndex = 0;
         // 
         // label2
         // 
         this.label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label2.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label2.Location = new System.Drawing.Point(320, 40);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(312, 40);
         this.label2.TabIndex = 0;
         // 
         // label3
         // 
         this.label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label3.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label3.Location = new System.Drawing.Point(8, 80);
         this.label3.Name = "label3";
         this.label3.Size = new System.Drawing.Size(312, 40);
         this.label3.TabIndex = 0;
         // 
         // label10
         // 
         this.label10.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
         this.label10.ImageAlign = System.Drawing.ContentAlignment.TopRight;
         this.label10.Location = new System.Drawing.Point(320, 200);
         this.label10.Name = "label10";
         this.label10.Size = new System.Drawing.Size(312, 40);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -