DELPHI 中让嵌入窗体的 WebBrowser 控件无边框


本文整理自网络,侵删。

 需要用到 TWebBrowser 控件。出现了一个问题:WebBrowser 组件在未载入 HTML 之前是无边框的,当载入 HTML 之后,WebBrowser 四周出现了一个三维边框,和程序本身的风格极不协调。经过测试以后发现,该边框并不是 WebBrowser 产生的,而是 WebBrowser 中载入的 HTML 产生的。后来真接用 CSS 去掉了边框,在网上找到的资料好像也是用这种方法。但是,如果修改每个页面的CSS,好像不是很理想的解决方案。最后自己通过验证,发现以下代码基本上解决了这个问题。

{ WB_Set3DBorderStyle }

procedure WB_Set3DBorderStyle(Sender: TWebBrowser; bValue: Boolean);
var
Document: IHTMLDocument2;
Element: IHTMLElement;
StrBorderStyle: string;
begin
//去掉边框
try
Document := TWebBrowser(Sender).Document as IHTMLDocument2;
if Assigned(Document) then
begin
Element := Document.Body;
if Element <> nil then
begin
case BValue of
False: StrBorderStyle := 'none';
True: StrBorderStyle := '';
end;
Element.Style.BorderStyle := StrBorderStyle;
end;
end;
except
//..
end;
end;

相关阅读 >>

Delphi xe5 json

Delphi 密码框写完后按enter直接登录

Delphi createdir 建立文件夹路径

Delphi nethttpclient1 数据库查询

Delphi 解决idtcpclient和idtcpserver通信中文乱码问题

Delphi 如何在窗体标题栏添加按钮

Delphi 获取中文/数字星期的函数

Delphi著名皮肤控件库大全评测

Delphi 全局键盘钩子(wh_keyboard)

Delphi10.x dpr文件

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...