delphi 中让嵌入窗体的 WebBrowser 控件无边框  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;
推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.048859119415283 seconds