简体   繁体   English

如何在不使用Web浏览器的情况下呈现HTML元素?

[英]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.

相关问题 如何在没有ID的Web浏览器中获取html元素 - How to get html element in web browser without an id 如何使用 Javascript 随机更改计时器上的 HTML 元素 - 跨越 web,而不仅仅是在浏览器中? - How do I randomly change an HTML element on a timer using Javascript - across the web, not just within the browser? 如何在浏览器中将标签呈现为html - How to render tags as html in browser 如何将动态变化的变量从 python 传递到 HTML 并让浏览器重新呈现新数据而不重新加载整个网页? - How to pass a dynamically changing variable from python to HTML and get the browser to re-render the new data without reloading the whole web-page? 是否可以在不使用Javascript的情况下检索Web引擎中的HTML元素? - Is it possible to retrieve HTML element in web engine without using Javascript? ExtJS - 如何呈现html元素 - ExtJS — how to render an html element 带有html元素的Web浏览器上的Submit按钮 - Submit button on web browser with html element 如何强制Web浏览器呈现Ajax响应,即整个HTML页面? - How can force web browser to render Ajax response, which is whole html page? 如何在不知道数据的情况下呈现动态表? 使用HTML和JS - How to render dynamic table without knowing the data? using HTML and JS 如何在不使用MathML的情况下在html中呈现嵌套的平方根? - How to render nested square roots in html without using MathML?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM