从浏览器控制创建窗口实例 [英] Creating Instance of window from from browser contol
问题描述
使用浏览器控件时是否可以创建窗口表单的实例.即,当我单击Web内容内的链接时,即
Is it possible to create an instance of window form when using browser control. i.e when i click on link inside web contents i.e
<a href="#">Open Form</a>
.
推荐答案
亲爱的朋友,
这些链接将对您有所帮助:-
http://www.codeproject.com/Articles/50544/Using- -WebBrowser-Control-in-ASP-NET [ ^ ]
http://msdn.microsoft.com/en-us/library/360kwx3z%28v = vs.90%29.aspx [ ^ ]
扩展的.NET 2.0 WebBrowser控件 [
Dear Friend,
These links will be helpful:-
http://www.codeproject.com/Articles/50544/Using-the-WebBrowser-Control-in-ASP-NET[^]
http://msdn.microsoft.com/en-us/library/360kwx3z%28v=vs.90%29.aspx[^]
Extended .NET 2.0 WebBrowser Control[^]
Please don''t forget to mark this as your answer if it helps you out.
Thanks
这是我想出的"hack".
1.创建了一个简单的名为"MakeNewWindow.txt"的文本文件...这里的内容无关紧要.我把它放在机器的桌面上.
2.创建了一个名为"MakeNewWindow.html"的简单HTML测试文件:
Here''s the "hack" I came up with.
1. created a simple text file named "MakeNewWindow.txt" ... it''s content doesn''t matter here. I put it on the Desktop of my machine.
2. created a simple HTML test file named "MakeNewWindow.html" :
<html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<a href="C:\Users\Ur\Desktop\MakeNewWindow.txt">Click here</a>
</body>
</html>
将其放在我的计算机的桌面上.
创建了一个简单的WinForm测试平台项目:
1.主要表格''form1:
a.在其上放一个WebBrowser控件''webBrowser1
b.在上面放一个TextBox控件''textBox1
c.为''form1
创建了一个Form_Load EventHandler
d.为''webBrowser1创建了一个webBrowser1_Navigating EventHandler
2.第二种形式''form2:只是一个空白形式
这是``form1:
Put that on the Desktop of my machine.
Created a simple WinForm test bed project:
1. main form, ''form1 :
a. put a WebBrowser control on it ''webBrowser1
b. put a TextBox control on it ''textBox1
c. created a Form_Load EventHandler for ''form1
d. created a webBrowser1_Navigating EventHandler for ''webBrowser1
2. second form ''form2 : just a blank form
Here''s the code for ''form1:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string HTMLPath=@"C:\Users\Ur\Desktop\MakeNewWindow.html";
private string URLPath=@"C:\Users\Ur\Desktop\MakeNewWindow.txt";
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
// is the navigation target a file ?
if (e.Url.IsFile)
{
// it is a file
// does the LocalPath property of the file
// contain the path of the .txt file we have specified ?
if (e.Url.LocalPath.Contains(URLPath))
{
// criteria met: make new instance of Form2, bring to front
Form2 newForm2 = new Form2();
newForm2.Show();
newForm2.BringToFront();
// cancel any further reaction to the link being clicked
e.Cancel = true;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate(HTMLPath);
}
}
的代码
因此,当应用程序启动时:
1.执行表单1"的表单加载事件处理程序
a. ''webBrowser1导航到指定的html文件并显示它
2.当正在运行的应用程序的用户单击显示的HTML文件中的一个链接时:
a.将调用webBrowser1_Navigating EventHandler:请参阅代码中的注释,以了解在那里发生的确切情况:确定是否创建Form2的新实例.
感觉就像是一种"hack",我衷心希望有人会带来更好的答案!
So when the application is launched:
1. The Form Load EventHandler of ''form 1 executes
a. ''webBrowser1 navigates to the html file specified, and displays it
2. When the user of the running application clicks on the one link in the displayed HTML file:
a. the webBrowser1_Navigating EventHandler is called: see the comments in the code for an explanation of exactly what happens there: which determines whether a new instance of Form2 is created, or not.
Feels like kind of a "hack," and I sincerely hope someone will come along with a better answer !
这篇关于从浏览器控制创建窗口实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!