#前言#

        最近这个北方的天气啊经常下雪,让我想起来我上学时候写的那个天气预报小功能了,今天又复现了一下,哈哈哈,大家当个乐子看哈!

1.创建项目

2.添加引用

上图所示,下载所需天气预报标识,网站地址:WeatherWebService Web 服务

注意是添加服务引用,咱们引用的是服务。

3.界面实现

下面是代码:

        private void button1_Click(object sender, EventArgs e)         {             FrmWeatherForecast.cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService();             if (string.IsNullOrEmpty(this.textBox1.Text.Trim()))             {                 MessageBox.Show("请输入要查询的城市名称!");                 return;             }             string[] r = w.getWeatherbyCityName(this.textBox1.Text.Trim());             this.textBox3.Text = string.Format("地区描述:{0}", "\r\n") +r[22].ToString();              this.textBox2.Text = string.Format(" 当前时间: {0}{1} 当前气温:{2}{1} 当前天气:{3}{1} 当前风级:{4}{1}", r[4].ToString(),"\r\n", r[5].ToString(),r[6].ToString(), r[7].ToString());             this.pictureBox1.Image = Image.FromFile(string.Format(@"weather/{0}", r[8].ToString()));// 从本地文件加载图片到 PictureBox。             this.pictureBox2.Image = Image.FromFile(string.Format(@"weather/{0}", r[9].ToString())); // 从本地文件加载图片到 PictureBox。               pictureBox1.Refresh(); // 刷新 PictureBox 以显示新图片。               pictureBox2.Refresh(); // 刷新 PictureBox 以显示新图片。         }

4.效果展示

精彩内容

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。