• C# 实现天气预报


    【转载】

    先添加Web引用http://www.webxml.com.cn/WebServices/WeatherWebService.asmx

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Windows.Forms;

     

    namespace WindowsFormsApplication1

    {

        public partial class FrmWeahter : Form

        {

            public FrmWeahter()

            {

                InitializeComponent();

            }

            //实例化天气预报服务

            WeatherWebService.WeatherWebService weatherWebService = newWeatherWebService.WeatherWebService();

            /// <summary>

            /// 获取省

            /// </summary>

            private void FrmWeahter_Load(object sender, EventArgs e)

            {

                string[] proveces = weatherWebService.getSupportProvince();// 获取省

                foreach (string provece in proveces)

                {

                    lbProvece.Items.Add(provece);

                }

            }

            /// <summary>

            /// 获取市

            /// </summary>

            private void lbProvece_SelectedIndexChanged(object sender, EventArgs e)

            {

                lbCity.Items.Clear();

                string[] citys = weatherWebService.getSupportCity(lbProvece.SelectedItem.ToString());//获取市

                foreach (string city in citys)

                {

                    lbCity.Items.Add(city.Substring(0, city.IndexOf(' ')));

                }

            }

            /// <summary>

            /// 查询天气结果

            /// </summary>

            private void lbCity_SelectedIndexChanged(object sender, EventArgs e)

            {

                txtWeather.Clear();

                string[] weathers = weatherWebService.getWeatherbyCityName(lbCity.SelectedItem.ToString());// 获取天气

                if (weathers[1].Trim() == "")

                {

                    MessageBox.Show("操作太快");

                    return;

                }

                //获取所有返回信息

                for (int i = 0; i < weathers.Length; i++)

                {

                    txtWeather.Text += weathers[i] + "        " + i.ToString() + " ";

                }

                string path = Application.StartupPath + @"weather";

                pictureBox1.Image = new Bitmap(path + weathers[8]);//天气趋势开始图片

                pictureBox2.Image = new Bitmap(path + weathers[9]);//天气趋势结束图片

                lblTemp.Text = weathers[5];//气温

                lblCity.Text = lbCity.SelectedItem.ToString();//城市

            }

     

        }

    }

  • 相关阅读:
    伪静态
    query 文件提交 +php后台入库
    PHP实现URL长连接转短连接方法
    通过经纬度获取所属城市信息
    PHP 学习之路1
    Linux云服务器安装tomcat
    linux下svn服务器搭建步骤
    HttpServletrequest 与HttpServletResponse总结
    HTML5基础
    Ajax相关总结
  • 原文地址:https://www.cnblogs.com/masonchi/p/3446133.html
Copyright © 2020-2023  润新知