C # Call WebService to create weather forecasts

Source: Internet
Author: User

Add Web reference: 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. Text;
Using System. Windows. Forms;

Namespace weather Assistant
{
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 ();

// Today
PictureBox01.ImageLocation = @ "images/weather/" + WeatherOfCity [8]. ToString ();
PictureBox02.ImageLocation = @ "images/weather/" + WeatherOfCity [9]. ToString ();
Label07.Text = WeatherOfCity [6]. ToString () + WeatherOfCity [5]. ToString () + WeatherOfCity [7]. ToString ();
Label08.Text = WeatherOfCity [11]. ToString ();

// Tomorrow
PictureBox03.ImageLocation = @ "images/weather/" + WeatherOfCity [15]. ToString ();
PictureBox04.ImageLocat

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.