看到puma大的这一篇(利用ASP.NET做一个结合Microsoft与Google翻译网页的小工具 ),刚好可以把他加入小喵自己平时工作计算机的首页中。
不过小喵稍稍的修改了一下用法,小喵结合的字典是【MSN的侧边字典】与【Yahoo字典】。使用MSN侧边字典的原因是,刚好他提供的侧边字典的宽度刚好可以放入小喵的首页中,相关程序代码如下:
补充:后来小喵再次做调整,增加了【InfoSeek日英字典】、【Google搜寻】与【Yahoo知识+】,如果有需要的人可以自己在加上自己常用的搜寻。
画面的部分:
小喵以Div里面放iframe的方式呈现结果。另外透过重迭的Div做出类似窗口的视觉效果。
01 字典/搜寻:
02 <asp:DropDownList ID="ddlDictSrc" runat="server">
03 <asp:ListItem Value="MCE">(字典)MSN字典(繁英)</asp:ListItem>
04 <asp:ListItem Value="YahooCE">(字典)Yahoo(繁英)</asp:ListItem>
05 <asp:ListItem Value="IJE">(字典)InfoSeek(和英)</asp:ListItem>
06 <asp:ListItem Value="YKM">(搜寻)知识+</asp:ListItem>
07 <asp:ListItem Value="Google">(搜寻)Google</asp:ListItem>
08 </asp:DropDownList>
09 <asp:TextBox ID="txtWord" runat="server"></asp:TextBox>
10 <asp:Button ID="btnStartDict" runat="server" Text="翻译/搜寻" />
11 <div id="divDict" runat="server" visible="false">
12 <div style="position:absolute; width: 640px; height: 480px; top: 90px; left: 50px; background-color: #333333;"></div>
13 <div style="position:absolute; width: 640px; height: 480px; top: 70px; left: 30px; background-color: #FFCC99;">
14 <div style="background-color:#800000; color:White; text-align: center;">
15 字典/搜寻
16 <asp:Button ID="btnClsDict" runat="server" Text="关闭" />
17 </div>
18 <iframe id="ifrmDict" name="ifrmDict" runat="server" width="640px" height="460px"></iframe>
19 </div>
20 </div>
CodeFile的部分:
01 Protected Sub btnStartDict_Click() Sub btnStartDict_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnStartDict.Click
02 '微软翻译网址
03 Dim MUrl As String = "http://dic.lifestyle.msn.com.tw/dict/word?k="
04 'Yahoo翻译网址
05 Dim YUrl As String = "http://tw.dictionary.yahoo.com/search?ei=UTF-8&p="
06 'InfoSeek翻译网址
07 Dim IUrl As String = "http://dictionary.www.infoseek.co.jp/?spa=1&sc=1&se=on&lp=0&gr=ml&qt=@@sWord&sm=1&sv=2T"
08 'Yahoo知识+网址
09 Dim YKMUrl As String = "http://tw.search.yahoo.com/search/kp?fr=sfp&ei=UTF-8&p="
10 'Google搜寻
11 Dim GoogleUrl As String = "http://www.google.com.tw/search?hl=zh-TW&q=@@sWord&meta=&aq=f"
12
13 '最后网址
14 Dim Url As String = ""
15
16 '要翻译的文字
17 Dim sWord As String = Server.UrlEncode(Me.txtWord.Text)
18
19 Select Case Me.ddlDictSrc.SelectedValue
20 Case "MCE"
21 Url = MUrl & sWord
22
23 Case "YahooCE"
24 Url = YUrl & sWord
25
26 Case "IJE"
27 Url = Replace(IUrl, "@@sWord", sWord)
28
29 Case "YKM"
30 Url = YKMUrl & sWord
31
32 Case "Google"
33 Url = Replace(GoogleUrl, "@@sWord", sWord)
34
35 End Select
36 Me.divDict.Visible = True
37 Me.ifrmDict.Attributes.Add("src", Url)
38 End Sub
执行结果如下:图片点击放大
条件输入:Yahoo字典,搜寻NDS
搜寻结果:

条件改为Yahoo知识+,结果:
