新建WinForm 项目;

点击添加服务引用》点击高级》点击添加Web引用:在URl输入http://www.webxml.com.cn/WebServices/WeatherWebService.asmx,点击转到,点击添加引用

C# WinForm实现获得某个城市天气情况;

按钮点击事件:

         /// <summary>
        /// 获取天气
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService();
            string[] s = new string[23];//声明string数组存放返回结果  
            string city = this.textBox1.Text.Trim();//获得文本框录入的查询城市  
            s = w.getWeatherbyCityName(city);
            if (s[8] == "")
            {
              //  MessageBox.Show("输入错误,请重新输入", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
               textBox2.Text = s[1] + " " + s[6]+ s[10];
            }   
        }

效果:

C# WinForm实现获得某个城市天气情况;

 

 

 

相关文章:

  • 2021-10-29
  • 2021-09-20
  • 2021-10-16
  • 2021-11-06
  • 2021-11-04
  • 2021-11-06
  • 2021-11-04
  • 2021-08-01
猜你喜欢
  • 2021-09-15
  • 2021-11-29
  • 2021-11-16
  • 2021-12-02
  • 2021-11-16
  • 2021-11-29
  • 2021-11-04
相关资源
相似解决方案