C# 拖放到托管的浏览器控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drag and Drop to a hosted Browser control
提问by HS.
I have a WinForms program written on .NET 2 which hosts a webbrowser control and renders asp.net pages from a known server.
我有一个在 .NET 2 上编写的 WinForms 程序,它承载一个 webbrowser 控件并从已知服务器呈现 asp.net 页面。
I would like to be able to drag, say, a tree node from a treeview in my winforms app into a specific location in the hosted web page and have it trigger a javascript event there.
Currently, I can implement the IDocHostUIHandler
interface and getting drag\drop events on the browser control, then call Navigate("javascript:fire_event(...)")
on the control to execute a script on the page. However, I want this to work only when I drop data on a specificpart of the page.
我希望能够将树节点从我的 winforms 应用程序中的树视图拖动到托管网页中的特定位置,并在那里触发 javascript 事件。目前,我可以IDocHostUIHandler
在浏览器控件上实现界面和获取拖放事件,然后调用Navigate("javascript:fire_event(...)")
控件在页面上执行脚本。但是,我希望这仅在我将数据放置在页面的特定部分时才起作用。
One solution, I suppose, would be to bite the bullet and write a custom browser plugin in the form of an activex control, embed that in the location I want to drop to and let that implement the needed drag\drop interfaces.
我想,一种解决方案是咬紧牙关,以 activex 控件的形式编写一个自定义浏览器插件,将其嵌入我想要放置的位置,并让它实现所需的拖放界面。
Would that work? Is there a cleaner approach? Can I take advantage of the fact that the browser control is hosted in my app and provide some further level of interaction?
那行得通吗?有更清洁的方法吗?我是否可以利用浏览器控件托管在我的应用程序中这一事实并提供更深层次的交互?
回答by Justin Walgran
Take a look at the BrowserPlusproject at Yahoo.
看看雅虎的BrowserPlus项目。
It looks like they have built a toolkit so that you don't have to do the gritty work of writing the browser plugin yourself.
看起来他们已经构建了一个工具包,这样您就不必自己编写浏览器插件的艰巨工作。
回答by Ben Childs
If you can find out the on screen position of the part of the page you are interested in, you could compare this with the position of the mouse when you receive the drop event. I'm not sure how practical this is if you can get the info out of the DOM or whatnot.
如果您能找到您感兴趣的页面部分在屏幕上的位置,您可以将其与收到放置事件时鼠标的位置进行比较。如果您可以从 DOM 或其他内容中获取信息,我不确定这有多实用。
As an alternative could you implement the mouse events on the bit of the page using javascript?
作为替代方案,您可以使用 javascript 在页面的位上实现鼠标事件吗?