vs获取天气及预报

开始的设置详见:

https://blog.csdn.net/weixin_43653287/article/details/100178863?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162208262516780262513530%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=162208262516780262513530&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v29-1-100178863.pc_search_result_cache&utm_term=c%23%E8%8E%B7%E5%8F%96%E5%BD%93%E6%97%A5%E5%A4%A9%E6%B0%94&spm=1018.2226.3001.4187

应该还看了个帖子,暂时找不到了

网址现在改成http://ws.webxml.com.cn/WebServices/WeatherWS.asmx,替换下就好了。

需要注意的内容:这个网站每天早上九点更新当日天气,所以如果9点钟之前运行应显示明天和后天的天气;

                             网站会不定期维护,且有时会拒绝访问需要考虑未连接情况

            cn.com.webxml.www.WeatherWS w = new cn.com.webxml.www.WeatherWS();
            //把webservice当做一个类来操作 
            string[] s = new string[30];//声明string数组存放返回结果  
            string city = "潍坊";//获得文本框录入的查询城市 
            s = w.getWeather(city, "");
            try
            {
                //以文本框内容为变量实现方法getWeatherbyCityName ,获得所在地方的天气
                TimeSpan workStart = DateTime.Parse("9:00").TimeOfDay;
                TimeSpan nowTime = DateTime.Now.TimeOfDay;
                if (nowTime < workStart)//获取天气的网站每天上午9点更新当日天气,增加条件语句,9点之前打开读取明天及后天天气。
                {
                    pictureBox2.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[15] + "");//今日天气、温度
                    label13.Text = s[13];
                    label15.Text = s[12];
                    pictureBox4.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[20] + "");//明日天气、温度
                    label14.Text = s[18];
                    label16.Text = s[17];

                }
                else
                {
                    pictureBox2.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[10] + "");//今日天气、温度
                    label13.Text = s[8];
                    label15.Text = s[7];
                    pictureBox4.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[15] + "");//明日天气、温度
                    label14.Text = s[13];
                    label16.Text = s[12];
                }
                
            }
            catch
            {
                MessageBox.Show("天气网站正在维护,请暂时使用,2小时后打开检查,若仍有问题请联系制作人员进行调试", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.TopMost = true;//将该窗体置顶
            }

 

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值