只要花上一个小时,就可以用C#语言给心爱的TA定制一个WinForm天气闹钟,加上自己录制的闹铃,美哉美哉!天气数据来源于Web Service 接口(http://ws.webxml.com.cn/WebServices/WeatherWS.asmx)。
最终效果
操作步骤
1. 文件 --> 新建 --> 项目 -->Visual C# --> Windows 窗体应用程序
2. 在项目中的引用上点击鼠标右键,选择添加服务引用 --> 高级--> 添加 Web 引用
3. 在URL中填写天气Web Service:http://ws.webxml.com.cn/WebServices/WeatherWS.asmx,并点击右边的“前往”小图标,自动生成 Web 引用名,点击【添加引用】即可
4. 拖拽控件并编写逻辑代码
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 WeatherAlarmClock
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
cn.com.webxml.ws.WeatherWS w = null;
private void button1_Click(object sender, EventArgs e)
{
label_weather.Text = "";
try
{