Is it possible to autosize WebBrowser control?
I need to display some portion 开发者_如何学JAVAof html in my windows forms application. It's necessary that this html will be displayed without any scrollbars.
I tried to use WebBrowser control for my task, but it lacks of AutoSize property. Is it possible to determine minimal height necessary to display all contents without scrolling somehow?
Set ScrollBarsEnabled to false. Define the size based on your target minimum width. Add a handler to the webbrowser documentcompleted event as follows:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
WebBrowser1.Size = WebBrowser1.Document.Body.ScrollRectangle.Size
End Sub
Here's a link to a C# WebBrowser wrapper which may do what you need:
http://www.codeproject.com/KB/miscctrl/csEXWB.aspx?msg=2526724
To do what you need, I think you would access the document on the page and then the element you're displaying, and get its height and width properties, and then adjust your WebBrowser control to be a few pixels larger than that. I think the WebBrowser wrapper control in the link can do the first part of this task (get the element's height and width).
精彩评论