[英]How to render HTML element without using web browser?
Is there a way how to draw specific HTML element content on a canvas without using any web browser control ? 有没有办法在不使用任何Web浏览器控件的情况下在画布上绘制特定的HTML元素内容?
With this code I'm rendering the element to the form's canvas (just as an example). 使用此代码,我将元素呈现给窗体的画布(仅作为示例)。
It works though, but this code is not a good practice - see below, why... 它虽然有效,但这段代码不是一个好习惯 - 见下文,为什么......
uses
SHDocVw, MSHTML;
procedure TForm1.Button1Click(Sender: TObject);
var
WebBrowser: TWebBrowser;
HTMLElement: IHTMLElement;
HTMLRenderer: IHTMLElementRender;
begin
WebBrowser := TWebBrowser.Create(nil);
try
WebBrowser.ParentWindow := Application.Handle;
WebBrowser.Navigate('https://stackoverflow.com/questions/2975586/good-delphi-blogs');
while WebBrowser.ReadyState < READYSTATE_COMPLETE do
Application.ProcessMessages;
HTMLElement := (WebBrowser.Document as IHTMLDocument3).getElementById('question');
HTMLRenderer := (HTMLElement as IHTMLElementRender);
HTMLRenderer.DrawToDC(Canvas.Handle);
finally
HTMLElement := nil;
HTMLRenderer := nil;
WebBrowser.Free;
end;
end;
It's bad because 这很糟糕,因为
Is there a clean way to solve this using MSHTML ? 有没有一种干净的方法来解决这个使用MSHTML?
DrawToDC和IViewObject都需要TWebBrowser控件才能将文档实际呈现为目标DC。
Maybe you can try THtmlViewer? 也许你可以尝试THtmlViewer? http://code.google.com/p/thtmlviewer/
http://code.google.com/p/thtmlviewer/
见THTMLabel从TMS软件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.