英文:
How to Get the Current URL Adress From cef Browser c# winforms
问题
我可以翻译您的要求:
我想要从 C# WinForms 中的 CEF 浏览器获取当前 URL。每当浏览器加载一个 URL(访问一个网站)时,我希望该 URL 显示在 Form1 的 textBox1 中。
英文:
How can i get The current Url from cef browser c# winforms . i want URL to be displayed in textBox1 in Form1 Whenver browser loads a URL ( visit a website )
答案1
得分: 0
获取C# WinForms项目中CEF浏览器的当前URL,需要在您的代码中添加以下内容:
-
为浏览器创建一个地址更改事件。
-
将以下代码放入:
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
string url = e.Address; textBox1.Invoke(new Action(() => textBox1.Text = url));
例如:
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
{
string url = e.Address;
textBox1.Invoke(new Action(() => textBox1.Text = url));
}
在上述示例中,我们可以看到每当浏览器加载一个URL时,它会触发地址更改事件,并在事件中使用Invoke
方法获取URL。
英文:
To get the current URL from the CEF browser in a C# WinForms project, you need to add these things in your code:
-
Create an Address Changed Event for the browser.
-
Put this code in the:
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
string url = e.Address; textBox1.Invoke(new Action(() => textBox1.Text = url));
For Example:
private void chromiumWebBrowser1_AddressChanged(object sender, AddressChangedEventArgs e)
{
string url = e.Address;
textBox1.Invoke(new Action(() => textBox1.Text = url));
}
In the above example, we see that whenever the browser loads a URL, it triggers the address change event and, inside the event, we are getting the URL using the Invoke
method.
if any futher questions reply to this ANSWER
Regards Adit
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论