English 中文(简体)
摘自C# Winforms
原标题:Executing JavaScript code from C# Winforms

我正试图利用Winforms &执行Java;我想引用Java文本。 我需要用谷歌翻译服务翻译几条线。 我参加了这部 n字典,其中翻译了电文,并在警示箱中显示:

<html>
<head>
<script type= text/javascript  src= http://www.google.com/jsapi ></script>
<script type= text/javascript >
google.load( language , 1 );
function init () {
google.language.translate( How are you? ,  en ,  es , function (translated) {
    alert(translated.translation);
});
}
google.setOnLoadCallback(init);
</script>
</head>
    <body>
    </body>
</html> 

是否有办法使我能通过任何扼杀,而不是你怎么办? 和amp;如果我能够把C# WinForms背景下的翻译文本(从警示箱或使用var)上调。

最佳回答

奥基我做了一些研究。 因此,在您的表格中添加一个浏览器,否则我将为你工作。

    public Form1()
    {
        InitializeComponent();
        webBrowser1.ObjectForScripting = new MyScript();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        string myTranslatedText = "Hello, how are you?";
        webBrowser1.DocumentText = @"
            <html>
            <head>
                <script type= text/javascript  src= http://www.google.com/jsapi ></script>
                <script type= text/javascript >
                    google.load( language , 1 );
                    function init () {
                    google.language.translate( " + myTranslatedText + @" ,  en ,  es , function (translated) {
                        window.external.CallServerSideCode(translated.translation);
                    });
                    }
                    google.setOnLoadCallback(init);                        
                </script>
            </head>
                <body>
                </body>
            </html>";
    }
    [ComVisible(true)]
    public class MyScript
    {
        public void CallServerSideCode(string myResponse)
        {
            Console.WriteLine(myResponse); //do stuff with response
        }
    }
问题回答

暂无回答




相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签