2012-03-23 84 views
0

你可以得到的文本執行以下操作:如何使用IHTMLSelectionObject獲取圖像?

IHTMLSelectionObject selection = htmlDocument.selection; 

    IHTMLTxtRange range = selection.createRange() as IHTMLTxtRange; 

但是如果我選擇它不會複製圖像標籤的圖像。如果你選擇一個圖像怎麼做得到它返回<img..>標籤?

回答

1

我終於想出了答案。

它很簡單:

IHTMLSelectionObject selection = htmlDocument.selection; 

IHTMLTxtRange range = selection.createRange() as IHTMLTxtRange; 
string html = range.htmlText; 
1

原諒我Pascal語法:

var 
    Selection: IHTMLSelectionObject; 
    CtlRange: IHTMLControlRange; 
    ImgElement: IHTMLImgElement; 

Selection:=(WB.Document as IHTMLDocument2).selection; 
if Selection.type_ = 'Control' then 
begin 
    CtlRange:=Selection.createRange as IHTMLControlRange; 
    ImgElement:=CtlRange.item(0); 
    // FileName:=ImgElement.src; 
end; 
相關問題