I've been trying to enable Autocomplete for forms in a System.Windows.Forms.WebBrowser
control.
Internet Explorer provides this with the Internet Options->Content->Autocomplete->Use Autocomplete for Forms
option. With this enabled, when you start typing "a" into an HTML element, it shows a list of your previous entries starting with "a" (maybe "apple" and "android"). I want the same thing in my WebBrowser control.
I've implemented IDocHostUIHandler
in my class, and made GetHostInfo
set the DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE
flag, but the flag doesn't seem to do anything. Other flags such as DOCHOSTUIFLAG.DOCHOSTUIFLAG_NO3DBORDER
work as expected, so I know that GetHostInfo
is getting called.
Some people report success from setting this flag, while others don't: http://microsoft.public.inetsdk.programming.webbrowser-ctl.narkive.com/MSQ6nobe/can-t-get-autocomplete-to-work-in-hosted-webbrowser-control
http://www.44342.com/webbrowser-control-f125-t1436-p1.htm
I call ICustomDoc.SetUIHandler(this as IDocHostUIHandler)
in my WebBrowser's DocumentCompleted
method so that the IDocHostUIHandler interface methods get called by MSHTML.
I thought that it might be relevant to make sure that my application is reading the registry key HKCU\Software\Microsoft\Internet Explorer\Main\Use FormSuggest
correctly, perhaps by implementing IDocHostUIHandler.GetOptionKeyPath
or IDocHostUIHandler.GetOverrideKeyPath
as suggested by people elsewhere. I tried implementing these, but I could not manage to make either of them get called.
I used the Process Monitor tool to check which registry keys my application was querying, and Use FormSuggest
was not being queried at all. It was trying to query HKCU\Software\Policies\Microsoft\Internet Explorer\Control Panel\FormSuggest
, but modifying this key did not seem to have any effect.
Is there anything further that I could do to get Autocomplete working? Thanks.
The following worked for me: (tested using my wordpress url)
Go to this stackoverflow thread and copy the ImprovedBrowser
answer: WebBrowser: Drag&Drop
Then replace the DocHostUIFLAG
with:
(the one in the original post only has a partial list)
You can read the descriptions of the flag values on MSDN DOCHOSTUIFLAG Enumerated Type
[Flags]
public enum DOCHOSTUIFLAG
{
DIALOG = 0x00000001,
DISABLE_HELP_MENU = 0x00000002,
NO3DBORDER = 0x00000004,
SCROLL_NO = 0x00000008,
DISABLE_SCRIPT_INACTIVE = 0x00000010,
OPENNEWWIN = 0x00000020,
DISABLE_OFFSCREEN = 0x00000040,
FLAT_SCROLLBAR = 0x00000080,
DIV_BLOCKDEFAULT = 0x00000100,
ACTIVATE_CLIENTHIT_ONLY = 0x00000200,
OVERRIDEBEHAVIORFACTORY = 0x00000400,
CODEPAGELINKEDFONTS = 0x00000800,
URL_ENCODING_DISABLE_UTF8 = 0x00001000,
URL_ENCODING_ENABLE_UTF8 = 0x00002000,
ENABLE_FORMS_AUTOCOMPLETE = 0x00004000,
ENABLE_INPLACE_NAVIGATION = 0x00010000,
IME_ENABLE_RECONVERSION = 0x00020000,
THEME = 0x00040000,
NOTHEME = 0x00080000,
NOPICS = 0x00100000,
NO3DOUTERBORDER = 0x00200000,
DISABLE_EDIT_NS_FIXUP = 0x00400000,
LOCAL_MACHINE_ACCESS_CHECK = 0x00800000,
DISABLE_UNTRUSTEDPROTOCOL = 0x01000000,
HOST_NAVIGATES = 0x02000000,
ENABLE_REDIRECT_NOTIFICATION = 0x04000000,
USE_WINDOWLESS_SELECTCONTROL = 0x08000000,
USE_WINDOWED_SELECTCONTROL = 0x10000000,
ENABLE_ACTIVEX_INACTIVATE_MODE = 0x20000000,
DPI_AWARE = 0x40000000
}
Then change the GetHostInfo
to:
int NativeMethods.IDocHostUIHandler.GetHostInfo(ref NativeMethods.DOCHOSTUIINFO info)
{
var ret = _baseIDocHostUIHandler.GetHostInfo(ref info);
// must be done after because base.GetHostInfo(...) resets the flags
info.dwFlags = info.dwFlags | (int) NativeMethods.DOCHOSTUIFLAG.ENABLE_FORMS_AUTOCOMPLETE;
return ret;
}