【小技能】C#写入html文件实现连接有道词典API

有道词典提供了API,在网站中可以直接调用,所以可以C#写入html文件实现连接有道词典API

(1)自己写一个网页,可以直接搜索有道API,相关页面有详细说明;

(2)通过c#的webBrower调用网页;

(3)获取textBox中的输入,写入html文件

(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 youdaoAPI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string tex = textBox1.Text;
            HtmlElement el = webBrowser1.Document.CreateElement("DIV");
            el.InnerHtml = "<span style=\"color:red\">" + tex + "</span>";
            webBrowser1.Document.Body.AppendChild(el);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                string str = "file:///C:/Users/user/Desktop/webtest.html";//一定要注意改路径!!!html文件的存放位置
                webBrowser1.Navigate(new Uri(str)); 	//打开网站
                //this.Text = str; //将打开的网址设置为标题栏

            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message.ToString()); }
        }
    }
}

效果图:


附上下载地址http://download.csdn.net/detail/gny315/8633649

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值