2

I'm trying to remove the scrollbars and border from a TWebBrowser. I've found loads of references to the following code and it works fine when used on www.google.com:

// Switch off scrollbars
WB.OleObject.document.body.style.overflowX := 'hidden';
WB.OleObject.document.body.style.overflowY := 'hidden';

// Switch off borders
WB.OleObject.document.body.style.borderstyle := 'none';

However, using a web page generated by ASP.NET, it no longer works.

Here's the ASP.NET aspx code:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test</title>
</head>
<body bgcolor="#333333" border="0">
    <form id="form1" runat="server">
    <table style="width:100%;">
        <tr>
            <td class="style7">
                <asp:Label ID="Label2" runat="server" Font-Names="Arial" Font-Size="21pt" 
                    ForeColor="#F2F2F2" Text="Test"></asp:Label>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

...and here's the HTML generated by the ASP.NET application:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
    Test
</title></head>
<body bgcolor="#333333" border="0">
    <form method="post" action="Default.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODExMDE5NzY5ZGSKCPuFcF0SPBHrn5HUkzHPVjgZoCXwtqbgbPjoAyOPAQ==" />
</div>

    <table style="width:100%;">
        <tr>
            <td class="style7">
                <span id="Label2" style="color:#F2F2F2;font-family:Arial;font-size:21pt;">Test</span>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

Any idea why the scrollbars/borders are still visible?

norgepaul
  • 6,013
  • 4
  • 43
  • 76
  • Could you post the text of your DFM? Without any code, if I load the page into a WebBrowser 350 high by 500 wide, Aligh = alNone, I get no horizontal scrollbar, only a vertical one with no thumb, whereas with Align = alTop, I don't get either scrollbar. – MartynA Aug 28 '14 at 15:35
  • 1
    In what IE mode are you running TWebbrowser (ie [FEATURE_BROWSER_EMULATION](http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control))? – whosrdaddy Aug 28 '14 at 15:37
  • @MartynA - I'm home now, so can't post the code, but it's super simple in my test app. Just a TWebBrowser dropped on a form (no alignment set, all properties left as default) with 2 buttons. One button navigates to the URL, the other tries to remove the scrollbars and border. – norgepaul Aug 28 '14 at 16:20
  • @whosrdaddy - I'm not sure what mode IE is running in, but I haven't changed anything so it must be the default mode. – norgepaul Aug 28 '14 at 16:20
  • 1
    So that basically means that your page is running by default in IE7 compatibility mode. Try adding the registry key like stated in the linked article and see if that solves your problem... – whosrdaddy Aug 28 '14 at 17:56
  • Forget my request for the DFM for now. I've tried again with a new WebBrowser off the palette in D7 & XE6, leaving all properties at their defaults, and in both cases I get a thumbless vertical sb and no horiz one. The vertical on stays there despite attempting to get rid of it by your method and ShowScrollBars(). Fwiw, my display is set at 96 dpi, standard text size. – MartynA Aug 29 '14 at 06:43
  • @MartynA - That's exactly what I see. Glad somebody else can repeat it – norgepaul Aug 29 '14 at 12:26
  • @whosrdaddy - I tried changing FEATURE_BROWSER_EMULATION suggestion. Unfortunately, it doesn't seem to help. – norgepaul Aug 29 '14 at 12:34
  • Curiously, I can't now reproduce what I saw yesterday, namely no scrollbars with the WB's Align set to alTop. If I'd been able to, I was going to try embedding the WB in a TPanel. Oh dear. – MartynA Aug 29 '14 at 12:36

1 Answers1

2

Focusing on Browser Emulation

As you say it works before and you have put a tag internet-explorer-11, I think the problem is more or less related to page rendering policy. So the solution could be FEATURE_BROWSER_EMULATION. Can you confirm that the problem occurs with MSIE11 only?

In case of FEATURE_BROWSER_EMULATION, you should add an entry into Registry with the application name as key. The value should be a corresponding emulation flag. For better troubleshooting, please paste related code.

Here is my proven code that can change rendering policy for your application. You can give a try.

const
  BROWSER_EMULATION_MSIE11_FORCED = 11001;
  BROWSER_EMULATION_MSIE11 = 11000; // currently this is the best rendering engine we can have
  BROWSER_EMULATION_MSIE10_FORCED = 10001;
  BROWSER_EMULATION_MSIE10 = 10000;
  BROWSER_EMULATION_MSIE9_FORCED = 9999;
  BROWSER_EMULATION_MSIE9 = 9000;
  BROWSER_EMULATION_MSIE8_FORCED = 8888;
  BROWSER_EMULATION_MSIE8 = 8000;
  BROWSER_EMULATION_MSIE7 = 7000;

procedure SetBrowserEmulation(Value: Integer; const ExeName: string);
begin
  ChangeFeatureControlRegValue('FEATURE_BROWSER_EMULATION', ExeName, Value);
end;

procedure ChangeFeatureControlRegValue(const Feature, ExeName: string; Value: Integer);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
     if Reg.OpenKey('\Software\Microsoft\Internet Explorer\Main\FeatureControl\' + Feature, {CanCreate=}True) then
     begin
       try
         Reg.WriteInteger(ExeName, Emulation);
       finally
         Reg.CloseKey;
       end;
     end;
  finally
    Reg.Free;
  end;
end;

As a small promotion, you can use my dutil.sys.win32.registry.Writer to simplify the whole Registry accessing stuff.

procedure ChangeFeatureControlRegValue(const Feature, ExeName: string; Value: Integer);
begin
  TWriter.WriteUInt('\Software\Microsoft\Internet Explorer\Main\FeatureControl\' + Feature, ExeName, Value);
end;

Another Approach

A different approach is to override browser behaviour. Have you ever tried to implement IDocHostUIHandler and override IDocHostUIHandler::GetHostInfo. If you have tried the famous TEmbeddedWB component, you will find demo code of how to implement IDocHostUIHandler. The key thing is to set pInfo.dwFlags to include flag DOCHOSTUIFLAG_SCROLL_NO.

stanleyxu2005
  • 8,081
  • 14
  • 59
  • 94