Related KB Artcicle : 236312
<<http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q236/3/12.asp&NoWebContent=1>>
Attached find the code snippet for the same, I got this soem somewhere
in usenet.
I remember, I had some problems doing this way .But was able to
solve. If you need any help drop me a mail : nirmalkannan at
myfastmail dot com.
Cheers
Nirmal
<code snippet>
...
using mshtml;
using SHDocVw;
using System.Runtime.InteropServices;
...
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
///
public enum DOCHOSTUITYPE
{
DOCHOSTUITYPE_BROWSE = 0,
DOCHOSTUITYPE_AUTHOR = 1
}
public enum DOCHOSTUIDBLCLK
{
DOCHOSTUIDBLCLK_DEFAULT = 0,
DOCHOSTUIDBLCLK_SHOWPROPERTIES = 1,
DOCHOSTUIDBLCLK_SHOWCODE = 2
}
public enum DOCHOSTUIFLAG
{
DOCHOSTUIFLAG_DIALOG = 0x00000001,
DOCHOSTUIFLAG_DISABLE_HELP_MENU = 0x00000002,
DOCHOSTUIFLAG_NO3DBORDER = 0x00000004,
DOCHOSTUIFLAG_SCROLL_NO = 0x00000008,
DOCHOSTUIFLAG_DISABLE_SCRIPT_INACTIVE = 0x00000010,
DOCHOSTUIFLAG_OPENNEWWIN = 0x00000020,
DOCHOSTUIFLAG_DISABLE_OFFSCREEN = 0x00000040,
DOCHOSTUIFLAG_FLAT_SCROLLBAR = 0x00000080,
DOCHOSTUIFLAG_DIV_BLOCKDEFAULT = 0x00000100,
DOCHOSTUIFLAG_ACTIVATE_CLIENTHIT_ONLY = 0x00000200,
DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY = 0x00000400,
DOCHOSTUIFLAG_CODEPAGELINKEDFONTS = 0x00000800,
DOCHOSTUIFLAG_URL_ENCODING_DISABLE_UTF8 = 0x00001000,
DOCHOSTUIFLAG_URL_ENCODING_ENABLE_UTF8 = 0x00002000,
DOCHOSTUIFLAG_ENABLE_FORMS_AUTOCOMPLETE = 0x00004000,
DOCHOSTUIFLAG_ENABLE_INPLACE_NAVIGATION = 0x00010000,
DOCHOSTUIFLAG_IME_ENABLE_RECONVERSION = 0x00020000,
DOCHOSTUIFLAG_THEME = 0x00040000,
DOCHOSTUIFLAG_NOTHEME = 0x00080000,
DOCHOSTUIFLAG_NOPICS = 0x00100000,
DOCHOSTUIFLAG_NO3DOUTERBORDER = 0x00200000,
DOCHOSTUIFLAG_DELEGATESIDOFDISPATCH = 0x00400000
}
[ StructLayout( LayoutKind.Sequential )]
public struct DOCHOSTUIINFO
{
uint cbSize;
uint dwFlags;
uint dwDoubleClick;
[MarshalAs(UnmanagedType.BStr)] string pchHostCss;
[MarshalAs(UnmanagedType.BStr)] string pchHostNS;
}
[StructLayout( LayoutKind.Sequential )]
public struct tagMSG
{
IntPtr hwnd;
int lParam;
uint message;
tagPOINT pt;
uint time;
uint wParam;
}
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown ),
GuidAttribute("bd3f23c0-d43e-11cf-893b-00aa00bdce1a")]
public interface IDocHostUIHandler
{
[PreserveSig]
void ShowContextMenu(uint dwID, ref tagPOINT ppt,
[MarshalAs(UnmanagedType.IUnknown)] object pcmdtReserved,
[MarshalAs(UnmanagedType.IDispatch)]object pdispReserved);
[PreserveSig]
void GetHostInfo(ref DOCHOSTUIINFO pInfo);
[PreserveSig]
void ShowUI(uint dwID, [MarshalAs(UnmanagedType.Interface)] IntPtr
pActiveObject, [MarshalAs(UnmanagedType.Interface)] IntPtr
pCommandTarget, [MarshalAs(UnmanagedType.Interface)] IntPtr pFrame,
[MarshalAs(UnmanagedType.Interface)] IntPtr pDoc);
[PreserveSig]
void HideUI();
[PreserveSig]
void UpdateUI();
[PreserveSig]
void EnableModeless(int fEnable);
[PreserveSig]
void OnDocWindowActivate(int fActivate);
[PreserveSig]
void OnFrameWindowActivate(int fActivate);
[PreserveSig]
void ResizeBorder(ref tagRECT prcBorder,
[MarshalAs(UnmanagedType.Interface)] IntPtr pUIWindow, int
fRameWindow);
[PreserveSig]
void TranslateAccelerator(ref tagMSG lpmsg, ref Guid pguidCmdGroup,
uint nCmdID);
[PreserveSig]
void GetOptionKeyPath(ref string pchKey, uint dw);
[PreserveSig]
void GetDropTarget([MarshalAs(UnmanagedType.Interface)] IntPtr
pDropTarget, [MarshalAs(UnmanagedType.Interface)] ref IntPtr
ppDropTarget);
[PreserveSig]
void GetExternal(ref object ppDispatch);
[PreserveSig]
void TranslateUrl(uint dwTranslate, ref ushort pchURLIn, IntPtr
ppchURLOut);
[PreserveSig]
void FilterDataObject(IDataObject pDO, ref IDataObject ppDORet); }
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown ),
GuidAttribute("3050f3f0-98b5-11cf-bb82-00aa00bdce0b")]
public interface ICustomDoc
{
[PreserveSig]
void SetUIHandler(IDocHostUIHandler pUIHandler);
}
public class Form1 : System.Windows.Forms.Form, IDocHostUIHandler {
private AxSHDocVw.AxWebBrowser axWebBrowser1;
private Object refmissing = System.Reflection.Missing.Value;
// ... usual declarations for your form - textboxes, buttons etc. //
....
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
// The following is necessary before accessing any browser
properties:
// initialise the browser by navigating to a blank page.
string sAddr = "about
:Blank";
axWebBrowser1.Navigate(sAddr, ref refmissing, ref refmissing, ref
refmissing, ref refmissing);
IHTMLDocument2 hDoc = (IHTMLDocument2)axWebBrowser1.Document;
// The missing link! Set the UI handler for this browser to this
application!!
((ICustomDoc) hDoc).SetUIHandler((IDocHostUIHandler) this);
}
// other form code, event handlers, your code etc.
/************************************************** *************************
************/
//
// IDocHostUIHandler implementation
//
/************************************************** *************************
************/
public void ShowContextMenu(uint dwID, ref tagPOINT ppt,
[MarshalAs(UnmanagedType.IUnknown)] object pcmdtReserved,
[MarshalAs(UnmanagedType.IDispatch)]object pdispReserved)
{
Console.WriteLine("ShowContextMenu");
}
public void GetHostInfo(ref DOCHOSTUIINFO pInfo)
{
Console.WriteLine("GetHostInfo");
}
public void ShowUI(uint dwID, [MarshalAs(UnmanagedType.Interface)]
IntPtr pActiveObject, [MarshalAs(UnmanagedType.Interface)] IntPtr
pCommandTarget, [MarshalAs(UnmanagedType.Interface)] IntPtr pFrame,
[MarshalAs(UnmanagedType.Interface)] IntPtr pDoc)
{
Console.WriteLine("ShowUI");
}
public void HideUI()
{
Console.WriteLine("HideUI");
}
public void UpdateUI()
{
Console.WriteLine("UpdateUI");
}
public void EnableModeless(int fEnable)
{
Console.WriteLine("EnableModeless");
}
public void OnDocWindowActivate(int fActivate)
{
Console.WriteLine("OnDocWindowActivate");
}
public void OnFrameWindowActivate(int fActivate)
{
Console.WriteLine("OnFrameWindowActivate");
}
public void ResizeBorder(ref tagRECT prcBorder,
[MarshalAs(UnmanagedType.Interface)] IntPtr pUIWindow, int
fRameWindow)
{
Console.WriteLine("ResizeBorder");
}
public void TranslateAccelerator(ref tagMSG lpmsg, ref Guid
pguidCmdGroup, uint nCmdID)
{
Console.WriteLine("TranslateAccelerator");
}
public void GetOptionKeyPath(ref string pchKey, uint dw)
{
Console.WriteLine("GetOptionKeyPath");
}
public void GetDropTarget([MarshalAs(UnmanagedType.Interface)]
IntPtr pDropTarget, [MarshalAs(UnmanagedType.Interface)] ref IntPtr
ppDropTarget)
{
Console.WriteLine("GetDropTarget");
}
public void GetExternal(ref object ppDispatch)
{
Console.WriteLine("GetExternal");
}
public void TranslateUrl(uint dwTranslate, ref ushort pchURLIn,
IntPtr ppchURLOut)
{
Console.WriteLine("TranslateUrl");
}
public void FilterDataObject(IDataObject pDO, ref IDataObject
ppDORet)
{
Console.WriteLine("FilterDataObject");
}
}
}
</codesnippet>
"John Bowman" <<Remove this before reply>
jo*********@thermo.com> wrote in message news:<ef**************@TK2MSFTNGP09.phx.gbl>...
ISMAILRAJPUT,
That's what I was hoping for, but no click events appear in the list of
events in VS designer to implement. A few others do appear, but nothing
apparently useful. How can I get at the OnClick event when it's not there?
John
"ISMAILRAJPUT" <hu************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... Just a Guess
Right click event will occure but i think what you need is "Do not Handle
the Event" or if there is a contextmenu attached, remove it.
---------------------------------------------------------
"John Bowman jo*********@thermo.com>" <<Remove this before reply> wrote in
message news:Od**************@TK2MSFTNGP11.phx.gbl... Hi,
How can I disable the right click capability of the Web Browser control
that's on a form? I only want it to display the HTML, w/ no popup menu.
TIA,
--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@thermo.com