首 页技术文章资源下载WAP论坛用户中心繁體中文
设为首页
加入收藏
联系我们
您当前的位置:中国WAP技术门户网站 -> 技术文章 -> 手机编程 -> Win Mobile -> 基础知识 -> 文章内容 退出登录 用户管理
热门文章
· [转载] wap2.0技巧篇
· [转载] WAP 2.0简介
· WML语言基础(WAP建站...
· [转载] WAP/WEB网站建设
· JSP技术在WAP开发中...
· [图文] WML语言基础(WAP建站...
· WML语言基础(WAP建站...
· [转载] 《女性安全期测算》...
· [转载] 跟你详说WAP
· asp.net开发wap程序...
相关文章
· [图文] 移动电视Smartphone...
· 建立牢固的多功能Sm...
· [图文] 开发高效的Smartpho...
· [图文] 开发MS Smartphone ...
· [图文] 为 Microsoft Smart...
· [图文] 初识 Smart Device ...
· [图文] Smart Device Exten...
· [组图] 建立牢固的多功能Sm...
· [组图] 在Smartphone/Pocke...
· 开发Smartphone游戏...
 
SmartPhone手机上查看QQ天气预报
文章作者:wap001 [ 收藏此页到365Fav ]
文章来源:转载 [ 收藏此页到365Key ]
发布时间:2005-9-14 9:12:03 减小字体
文章编辑:小凯 增大字体


  三、新建手机应用程序项目

  1、新建一个智能设备应用程序,在主面板上拖放如图2所示的几个控件,其中timer是用来检查是否数据已经下载完毕的。


图1-新建智能设备应用程序



图2-界面设计



  2、引用建好的WebService


图3-引用WebService


  3、WeatherService智能手机上运行的程序源代码

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace WeatherService
{
 /// <summary>
 /// Summary description for MainForm.
 /// </summary>

 public class MainForm : System.Windows.Forms.Form
 {
  private System.Windows.Forms.ComboBox comboBox_City;
  private System.Windows.Forms.MenuItem menuItem1;
  private System.Windows.Forms.Label txt_Weather1;
  private System.Windows.Forms.Label txt_Date1;
  private System.Windows.Forms.Label txt_Temp1;
  private System.Windows.Forms.Label txt_WindPower1;
  private System.Windows.Forms.Label txt_Temp2;
  private System.Windows.Forms.Label txt_WindPower2;
  private System.Windows.Forms.Label txt_Date2;
  private System.Windows.Forms.Label txt_Weather2;
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem_Menu;
  private System.Windows.Forms.MenuItem menuItem_Exit;
  private System.Windows.Forms.Label label_City;
  private System.Windows.Forms.Timer timer1;
  private System.Windows.Forms.MenuItem menuItem2;
  private System.Windows.Forms.MenuItem menuItem3;

  public string[] cityList = new string[]
  {
   "北京",
   "上海",
   "天津",
   "石家庄",
   "哈尔滨",
   "沈阳",
   "长春",
   "太原",
   "济南",
   "郑州",
   "天津",
   "呼和浩特",
   "西安",
   "银川",
   "兰州",
   "西宁",
   "乌鲁木齐",
   "合肥",
   "南昌",
   "南京",
   "杭州",
   "武汉",
   "长沙",
   "广州",
   "深圳",
   "福州",
   "厦门",
   "南宁",
   "桂林",
   "海口",
   "重庆",
   "成都",
   "贵阳",
   "昆明",
   "拉萨",
   "香港",
   "澳门",
   "台北",
  };

  public MainForm()
  {
   InitializeComponent();
   foreach( string x in cityList)
   {
    this.comboBox_City.Items.Add(x);
   }

   this.comboBox_City.SelectedIndex = 0;
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>

  protected override void Dispose( bool disposing )
  {
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code

  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>

  private void InitializeComponent()
  {
   this.mainMenu1 = new System.Windows.Forms.MainMenu();
   this.menuItem1 = new System.Windows.Forms.MenuItem();
   this.menuItem_Menu = new System.Windows.Forms.MenuItem();
   this.menuItem_Exit = new System.Windows.Forms.MenuItem();
   this.menuItem3 = new System.Windows.Forms.MenuItem();
   this.menuItem2 = new System.Windows.Forms.MenuItem();
   this.comboBox_City = new System.Windows.Forms.ComboBox();
   this.label_City = new System.Windows.Forms.Label();
   this.txt_Weather1 = new System.Windows.Forms.Label();
   this.txt_Date1 = new System.Windows.Forms.Label();
   this.txt_Temp1 = new System.Windows.Forms.Label();
   this.txt_WindPower1 = new System.Windows.Forms.Label();
   this.txt_Temp2 = new System.Windows.Forms.Label();
   this.txt_WindPower2 = new System.Windows.Forms.Label();
   this.txt_Date2 = new System.Windows.Forms.Label();
   this.txt_Weather2 = new System.Windows.Forms.Label();
   this.timer1 = new System.Windows.Forms.Timer();

   //
   // mainMenu1
   //

   this.mainMenu1.MenuItems.Add(this.menuItem1);
   this.mainMenu1.MenuItems.Add(this.menuItem_Menu);
   //
   // menuItem1
   //

   this.menuItem1.Text = "确定";
   this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

   //
   // menuItem_Menu
   //

   this.menuItem_Menu.MenuItems.Add(this.menuItem_Exit);
   this.menuItem_Menu.MenuItems.Add(this.menuItem3);
   this.menuItem_Menu.MenuItems.Add(this.menuItem2);
   this.menuItem_Menu.Text = "菜单";

   //
   // menuItem_Exit
   //

   this.menuItem_Exit.Text = "退出";
   this.menuItem_Exit.Click += new System.EventHandler(this.menuItem_Exit_Click);

   //
   // menuItem3
   //

   this.menuItem3.Text = "-";

   //
   // menuItem2
   //

   this.menuItem2.Text = "关于";
   this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);

   //
   // comboBox_City
   //

   this.comboBox_City.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.comboBox_City.Location = new System.Drawing.Point(52, 8);
   this.comboBox_City.Size = new System.Drawing.Size(114, 22);

   //
   // label_City
   //

   this.label_City.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Bold);
   this.label_City.Location = new System.Drawing.Point(4, 12);
   this.label_City.Size = new System.Drawing.Size(52, 16);
   this.label_City.Text = "城市:";
   this.label_City.TextAlign = System.Drawing.ContentAlignment.TopCenter;

   //
   // txt_Weather1
   //

   this.txt_Weather1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Weather1.Location = new System.Drawing.Point(12, 50);
   this.txt_Weather1.Size = new System.Drawing.Size(152, 14);
   this.txt_Weather1.Text = "天气:";

   //
   // txt_Date1
   //

   this.txt_Date1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Date1.Location = new System.Drawing.Point(12, 34);
   this.txt_Date1.Size = new System.Drawing.Size(152, 14);
   this.txt_Date1.Text = "日期:";

   //
   // txt_Temp1
   //

   this.txt_Temp1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Temp1.Location = new System.Drawing.Point(12, 68);
   this.txt_Temp1.Size = new System.Drawing.Size(152, 14);
   this.txt_Temp1.Text = "气温:";

   //
   // txt_WindPower1
   //

   this.txt_WindPower1.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_WindPower1.Location = new System.Drawing.Point(12, 84);
   this.txt_WindPower1.Size = new System.Drawing.Size(152, 14);
   this.txt_WindPower1.Text = "风力:";

   //
   // txt_Temp2
   //

   this.txt_Temp2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Temp2.Location = new System.Drawing.Point(12, 140);
   this.txt_Temp2.Size = new System.Drawing.Size(152, 14);
   this.txt_Temp2.Text = "气温:";

   //
   // txt_WindPower2
   //

   this.txt_WindPower2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_WindPower2.Location = new System.Drawing.Point(12, 156);
   this.txt_WindPower2.Size = new System.Drawing.Size(152, 14);
   this.txt_WindPower2.Text = "风力:";

   //
   // txt_Date2
   //

   this.txt_Date2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Date2.Location = new System.Drawing.Point(12, 108);
   this.txt_Date2.Size = new System.Drawing.Size(152, 14);
   this.txt_Date2.Text = "日期:";

   //
   // txt_Weather2
   //

   this.txt_Weather2.Font = new System.Drawing.Font("Nina", 9F, System.Drawing.FontStyle.Regular);
   this.txt_Weather2.Location = new System.Drawing.Point(12, 124);
   this.txt_Weather2.Size = new System.Drawing.Size(152, 14);
   this.txt_Weather2.Text = "天气:";

   //
   // timer1
   //

   this.timer1.Interval = 200;
   this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

   //
   // MainForm
   //

   this.Controls.Add(this.comboBox_City);
   this.Controls.Add(this.txt_Date1);
   this.Controls.Add(this.txt_Weather1);
   this.Controls.Add(this.label_City);
   this.Controls.Add(this.txt_Temp1);
   this.Controls.Add(this.txt_WindPower1);
   this.Controls.Add(this.txt_Temp2);
   this.Controls.Add(this.txt_WindPower2);
   this.Controls.Add(this.txt_Date2);
   this.Controls.Add(this.txt_Weather2);
   this.Menu = this.mainMenu1;
   this.Text = "天气预报";
  }

  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>

  static void Main()
  {
   Application.Run(new MainForm());
  }

  private void menuItem_Exit_Click(object sender, System.EventArgs e)
  {
   this.Dispose();
  }

  private void menuItem1_Click(object sender, System.EventArgs e)
  {
   SearchWeather(this.comboBox_City.Text);
  }

  private string[] myString = new string[]
  {
    "日期: ",
    "温度: ",
    "天气: ",
    "风力: ",
  };

  public void SearchWeather(string cityName)
  {
   if( this.txt_Date1.Text != myString[0] )
   {
    ReSelect();
   }

   this.Text = "正在下载...";
   this.timer1.Enabled = true;

   WeatherService.Weather weather = new WeatherService.Weather();
   DataSet myDs = weather.GetWeatherDataSet(cityName);

   this.txt_Date1.Text = myString[0] + myDs.Tables[0].Rows[0]["Date1"].ToString();
   this.txt_Temp1.Text = myString[1] + myDs.Tables[0].Rows[0]["Temp1"].ToString();
   this.txt_Weather1.Text = myString[2] + myDs.Tables[0].Rows[0]["Weather1"].ToString();
   this.txt_WindPower1.Text = myString[3] + myDs.Tables[0].Rows[0]["WindPower1"].ToString();

   this.txt_Date2.Text = myString[0] + myDs.Tables[0].Rows[0]["Date2"].ToString();
   this.txt_Temp2.Text = myString[1] + myDs.Tables[0].Rows[0]["Temp2"].ToString();
   this.txt_Weather2.Text = myString[2] + myDs.Tables[0].Rows[0]["Weather2"].ToString();
   this.txt_WindPower2.Text = myString[3] + myDs.Tables[0].Rows[0]["WindPower2"].ToString();
  }

  private void ReSelect()
  {
   this.txt_Date1.Text = myString[0];
   this.txt_Temp1.Text = myString[1];
   this.txt_Weather1.Text = myString[2];
   this.txt_WindPower1.Text = myString[3];
   this.txt_Date2.Text = myString[0];
   this.txt_Temp2.Text = myString[1];
   this.txt_Weather2.Text = myString[2];
   this.txt_WindPower2.Text = myString[3];
  }

  private void timer1_Tick(object sender, System.EventArgs e)
  {
   if( this.txt_Date1.Text.IndexOf("月") != -1)
   {
    this.timer1.Enabled = false;
    this.Text = "天气预报";
   }
  }

  private void menuItem2_Click(object sender, System.EventArgs e)
  {
   this.Text = "作者:贺星河";
   System.Threading.Thread.Sleep(3000);
   this.Text = "天气预报";
  }
 }
}

  

上一页  [1] [2] [3]  下一页

 
[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]

关于我们  |   版权声明  |   广告服务  |   帮助中心  |   联系我们  |   网站地图  |   友情链接 
Copyright © 2004-2005 Wapzj.Com. All Rights Reserved .
粤ICP备05000730号 在线人数: