I'm trying to get scrollbars working with the web browser control. However, as I'll be using it to display a message for a custom messagebox, I don't want the scrollbar to appear even if its not needed - as it seems to do by default. To circumvent this I decided to disable scrollbars on the control and instead use scrollbars on another control like a Panel. This way they'll only appear when the contents of the browser page is too big to fit.
This hasn't worked out too well, though I've read quite a few posts, even on StackOverflow, where this seems to be a valid solution. One example is when I tried using the solution here:
It seems as though if Scrollbars are disabled for the web browser, it won't let the panel use scrollbars either. This seemed to be the case when testing in design mode. To overcome this I tried adding a picture box behind the web browser inside the panel; it worked when in design mode (resizing the picture box and web browser would cause the panel to enable its scrollbars), but didn't work during runtime (I added code to have the picture box change to the size of the web browser control - which itself is always resized to fit the size of the scrollable contents).
I also tried programmatically enabling and disabling the web browser's scrollbars based on if the ScrollableRectangle size was bigger than the size of the control. This theoretically would be fine, except it seems to clear all text within the control any time the ScrollbarsEnabled property is changed - and thus is changed back to having no scrollbars.
I'm doing this with the following code, called effectively whenever a key is pressed in the control:
if (Output.Document.Body != null)
{
if (Output.Document.Body.ScrollRectangle.Size.Height > Output.Size.Height
|| Output.Document.Body.ScrollRectangle.Size.Width > Output.Size.Width)
Output.ScrollBarsEnabled = true;
else
Output.ScrollBarsEnabled = false;
}
else
Output.ScrollBarsEnabled = false;
It's also important to note that I also need a solution for the HTML editor which will be used within the app, so ideally any solution would not rely on a page load event etc... as these do not seem to trigger when the web browser has design mode set to on (which is needed for it to work as an HTML editor). However, in this particular situation I can fall back on enabling the default scrollbars if there's no better solution.
EDIT: To be clear, I am not talking about any scrollbars within the HTML content - that is of no concern as the HTML is simply being used to allow for flexible formatting of text. I'm talking only about the scrollbar of the browser control itself.
Any help much appreciated. Thanks!