I have a webBrowser
control named webBrowser1
that is added and docked as DockStyle.Full
on a custom user control. The web-browser accepts some HTML text dynamically and displays it. I disabled the scroll bars of the webBrowser
control. My problem is that whenever the content is somewhat lengthy, the webBrowser
hides it from below. But the requirement of my project objective is that the webBrowser must not show either scroll bars or it should not hide some of the content. The content must be completely shown as it is without scrolling. That means the user control on which the webBrowser
is docked must resize itself according to webBrowser
's content. So, can anyone please suggest me how to achieve this? I searched all over the internet and SO but found nothing.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You can get the current size of HTML window via WebBrowser.Document.Window.Size and resize the container control accordingly. Depending on how your
WebBrowser
control content receives dynamic updates, you'd probably need to do this after each update. You could also tryWebBrowser.Document.Body.ScrollRectangle
ifDocument.Window.Size
doesn't grow in the expected way.[EDITED] The following code works for me (IE10):
To resize your usercontrol you first need to get the size needed by the content. This can be achived with TextRender.MeasureText, like so:
In your case it's a bit more tricky, as the text contains HTML-tags wich needs to be filtered away, to get the correct height.. I belive this can be achived with RegEx or a simple algo wich removes all content between < and > from a string.. You may also have to create special handlig for some HTML-tags (I.E Lists)