Delphi 6 - 更改 TWebBrowser 组件上的光标
在我的 Delphi 6 Pro 程序中,我可以使用下面的代码成功更改 TWebBrowser 组件上的光标,但仅当它不包含有效的 Web 文档时:
const
theCursorID: integer = 1;
Screen.Cursors[theCursorID] := LoadCursorFromFile(PChar(theAniCursorFilename));
theWebBrowser.Cursor := theCursorID;
一旦加载 Web 文档,光标就会恢复为标准鼠标指针。我猜这是因为加载网络文档时底层窗口(句柄/画布/等)发生了变化。如何在加载网页文档时成功更改鼠标光标?
In my Delphi 6 Pro program I'm able to change the cursor on a TWebBrowser component successfully using the code below, but only when it does not contain a valid web document:
const
theCursorID: integer = 1;
Screen.Cursors[theCursorID] := LoadCursorFromFile(PChar(theAniCursorFilename));
theWebBrowser.Cursor := theCursorID;
As soon as a web document loads, the cursor reverts to the standard mouse pointer. I'm guessing it's because the underlying window (handle/canvas/etc.) changes when a web document is loaded. How can I successfully change the mouse cursor when a web document is loaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,TWebBrowser 是 IE 的包装器,它反过来显示一致的用户界面,包括用于在浏览器中“导航”的光标。例如,只要加载的网页包含超链接,它就会将光标更改为手形,让用户知道他/她可以单击该超链接。
我不知道有什么办法可以改变 Delphi 的这种行为,也许这是可能的。但是,如果您可以控制加载的网页(对我来说似乎是这样),您可以在该页面中编写光标更改的代码,因为它(仅)在 IE 中受支持。
如果您不能或不想修改 .css 文件,请将以下代码添加到页面的标题中:
或者,您可以直接修改页面上元素的样式,如下所示:
Remember TWebBrowser is a wraper for IE, which in turns shows a consistent user interface, including cursors used to "navigate" in the browser. For example, wherever the loaded web page contains hyperlinks, it will change the cursor to a hand to let the user know s/he can click on that hyperlink.
I know no way to change this behavior from Delphi, maybe it is possible. But, if you're in control of the loaded web-page (it seems the case to me), you can code in that page the cursor change, because it is supported (only) in IE.
If you cannot or do not want to modify your .css file, put the following code to the header of your page:
Alternatively, you can directly modify the style of an element on your page like this: