Hello,
I am trying to remove the scrollbars from any page I load up into the
browser control on a window form. I first tried the following:
browserDoc = (mshtml.HTMLDocument)browser.Document;
browserBody = (mshtml.HTMLBody)browserDoc.body;
browserBody.scroll = "no";
This worked for most pages but not all. When I navigated to the following
web site:
http://www.levaquinspeakers.com
It still showed the vertical scroll bar although it was disabled since no
scrolling was needed. On sites like http://www.microsoft.com it worked
perfectly. So I did a little research and found people saying that I should
use SetWindowLong API passing it the compliment of WS_VSCROLL and WS_HSCROLL
to turn off the scrollbars. Here is the code I used:
private const int CONST_GWL_STYLE = -16;
private const int CONST_WS_VSCROLL = 0x00200000;
private const int CONST_WS_HSCROLL = 0x00100000;
private const int CONST_SWP_NOSIZE = 0x0001;
private const int CONST_SWP_NOMOVE = 0x0002;
private const int CONST_SWP_NOZORDER = 0x0004;
private const int CONST_SWP_FRAMECHANGED = 0x0020;
private const int CONST_SET_WINDOW_POS_FLAGS = CONST_SWP_NOMOVE |
CONST_SWP_NOSIZE | CONST_SWP_NOZORDER | CONST_SWP_FRAMECHANGED;
//API Calls.
[ DllImport( "user32.dll", EntryPoint = "GetClientRect" ) ]
private static extern int GetClientRect (IntPtr hWnd, ref Rectangle lpRect);
[ DllImport( "user32.dll", EntryPoint = "GetWindowLong" ) ]
private static extern IntPtr GetWindowLongPtr (IntPtr hWnd, int nIndex);
[ DllImport( "user32.dll", EntryPoint = "SetWindowLong" ) ]
private static extern IntPtr SetWindowLongPtr (IntPtr hWnd, int nIndex,
IntPtr dwNewLong);
[ DllImport( "user32.dll", EntryPoint = "SetWindowPos" ) ]
private static extern int SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy, uint uFlags);
IntPtr windowStyle;
int returnValue;
windowStyle = GetWindowLongPtr(browser.Handle, CONST_GWL_STYLE);
windowStyle = new IntPtr(windowStyle.ToInt32() & ~CONST_WS_VSCROLL &
~CONST_WS_HSCROLL);
windowStyle = SetWindowLongPtr(browser.Handle, CONST_GWL_STYLE,
windowStyle);
returnValue = SetWindowPos(browser.Handle, new IntPtr(0), 0, 0, 0, 0,
CONST_SET_WINDOW_POS_FLAGS);
I tried with and without the SetWindowPos call at the end. When I step
through the code I get a proper windowStyle back but it seems the window
already has the WS_VSCROLL and WS_HSCROLL because doing an AND with there
compliments does not change the style at all.
Is there anyway I can get the browser control to reliably remove the
scrollbars? If not is it possible to determine when either the vertical or
horizontal are displayed along with there widths? Thank you for any help you
can provide!!!
Thanks,
Ken