There was a question posted on the forum asking how to block images similar to the way Outlook is doing it.

I have a sample in C# using .NET 2.0 implementing this functionality.

Download Source Code Here

For more information on customizing Internet Explorer - read here

The WebBrowser Control gives you control over what it downloads, displays, and executes. To gain this control, you need to implement your host’s IDispatch so it handles DISPID_AMBIENT_DLCONTROL. When the WebBrowser Control is instantiated, it will call your IDispatch::Invoke with this ID. Set pvarResult to a combination of following flags, using the bitwise OR operator, to indicate your preferences.

IE allows us to set certain flags to control Download and Execution. Here are a few of the flags

1. DLCTL_DLIMAGES, DLCTL_VIDEOS, and DLCTL_BGSOUNDS: Images, videos, and background sounds will be downloaded from the server and displayed or played if these flags are set. They will not be downloaded and displayed if the flags are not set.
2. DLCTL_NO_SCRIPTS and DLCTL_NO_JAVA: Scripts and Java applets will not be executed.
3. DLCTL_NO_DLACTIVEXCTLS and DLCTL_NO_RUNACTIVEXCTLS : ActiveX controls will not be downloaded or will not be executed.


Here is my solution.

1. I included the .NET 2.0 WebBrowser control in my form.
2. I implemented IOleClientSite COM Interface in my Form.
3. Next, I get the ActiveXInstance from my WebBrowser control and cast it to IOleObject. I then call SetClientSite passing my Form as input.

IOleObject obj = (IOleObject)this.webBrowser1.ActiveXInstance;
obj.SetClientSite(this);

4. Handle DISPID_AMBIENT_DLCONTROL in my form.

[DispId(-5512)]
public virtual int IDispatch_Invoke_Handler()
{
System.Diagnostics.Debug.WriteLine(”-5512″);
return (int)_options;
}

5. Lastly, but very importantly, make the Form COMVisible - if not, IDispatch_Invoke_Handler() will not be called.

[ComVisible(true)]
public partial class Form1 : Form, IOleClientSite