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.HTMLDoc ument)browser.D ocument;
browserBody = (mshtml.HTMLBod y)browserDoc.bo dy;
browserBody.scr oll = "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_VSCROL L = 0x00200000;
private const int CONST_WS_HSCROL L = 0x00100000;
private const int CONST_SWP_NOSIZ E = 0x0001;
private const int CONST_SWP_NOMOV E = 0x0002;
private const int CONST_SWP_NOZOR DER = 0x0004;
private const int CONST_SWP_FRAME CHANGED = 0x0020;
private const int CONST_SET_WINDO W_POS_FLAGS = CONST_SWP_NOMOV E |
CONST_SWP_NOSIZ E | CONST_SWP_NOZOR DER | CONST_SWP_FRAME CHANGED;
//API Calls.
[ DllImport( "user32.dll ", EntryPoint = "GetClientR ect" ) ]
private static extern int GetClientRect (IntPtr hWnd, ref Rectangle lpRect);
[ DllImport( "user32.dll ", EntryPoint = "GetWindowL ong" ) ]
private static extern IntPtr GetWindowLongPt r (IntPtr hWnd, int nIndex);
[ DllImport( "user32.dll ", EntryPoint = "SetWindowL ong" ) ]
private static extern IntPtr SetWindowLongPt r (IntPtr hWnd, int nIndex,
IntPtr dwNewLong);
[ DllImport( "user32.dll ", EntryPoint = "SetWindowP os" ) ]
private static extern int SetWindowPos (IntPtr hWnd, IntPtr hWndInsertAfter ,
int X, int Y, int cx, int cy, uint uFlags);
IntPtr windowStyle;
int returnValue;
windowStyle = GetWindowLongPt r(browser.Handl e, CONST_GWL_STYLE );
windowStyle = new IntPtr(windowSt yle.ToInt32() & ~CONST_WS_VSCRO LL &
~CONST_WS_HSCRO LL);
windowStyle = SetWindowLongPt r(browser.Handl e, CONST_GWL_STYLE ,
windowStyle);
returnValue = SetWindowPos(br owser.Handle, new IntPtr(0), 0, 0, 0, 0,
CONST_SET_WINDO W_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