添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營(yíng)銷、網(wǎng)站重做改版、平頂山網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場(chǎng)景定制、商城網(wǎng)站開(kāi)發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)公司、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁(yè)設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為平頂山等各大城市提供網(wǎng)站開(kāi)發(fā)制作服務(wù)。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 天氣助手
{
public partial class Weather : Form
{
public Weather()
{
InitializeComponent();
}
public string[] GetWeather(string xCity)
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] WeatherOfCity = mWeatherWebService.getWeatherbyCityName(xCity);
return WeatherOfCity;
}
private void Weather_Load(object sender, EventArgs e)
{
}
public void Weather_Shown(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mArea = mWeatherWebService.getSupportProvince();
int mCount = mArea.Length - 1;
comboBox01.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox01.Items.Add(mArea[mI].ToString());
}
comboBox01.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox01_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mCity = mWeatherWebService.getSupportCity(comboBox01.Text);
int mCount = mCity.Length - 1;
comboBox02.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox02.Items.Add(mCity[mI].Remove(mCity[mI].IndexOf("(")));
}
comboBox02.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox02_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string[] WeatherOfCity = GetWeather(comboBox02.Items[comboBox02.SelectedIndex].ToString());
label03.Text = WeatherOfCity[0].ToString();
label05.Text = WeatherOfCity[1].ToString();
label06.Text = WeatherOfCity[10].ToString();
//今天
pictureBox01.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[8].ToString();
pictureBox02.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[9].ToString();
label07.Text = WeatherOfCity[6].ToString() + WeatherOfCity[5].ToString() + WeatherOfCity[7].ToString();
label08.Text = WeatherOfCity[11].ToString();
//明天
pictureBox03.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[15].ToString();
pictureBox04.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[16].ToString();
label16.Text = WeatherOfCity[13].ToString() + WeatherOfCity[12].ToString() + WeatherOfCity[14].ToString();
//后天
pictureBox05.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[20].ToString();
pictureBox06.ImageLocation = @"p_w_picpaths/weather/" + WeatherOfCity[21].ToString();
label17.Text = WeatherOfCity[18].ToString() + WeatherOfCity[17].ToString() + WeatherOfCity[19].ToString();
//城市說(shuō)明及圖片
pictureBox07.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/" + WeatherOfCity[3].ToString();
label18.Text = WeatherOfCity[22].ToString();
//預(yù)計(jì)時(shí)間
label19.Text = "預(yù)報(bào)時(shí)間:" + WeatherOfCity[4].ToString();
}
catch
{
}
}
}
}