需要用到 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;