Implement IDispatch::Invoke to be called by a WebBrowser control

Here is a customized WebBrowser that allows you to change the DLCONTROL flags. This is an example code: public partial class Form1 : Form { private MyWebBrowser _webBrowser; public Form1() { InitializeComponent(); _webBrowser = new MyWebBrowser(); _webBrowser.Dock = DockStyle.Fill; Controls.Add(_webBrowser); } private void button1_Click(object sender, EventArgs e) { _webBrowser.DownloadControlFlags = (int)WebBrowserDownloadControlFlags.DOWNLOADONLY; _webBrowser.Navigate(“http://mysamplewebsite”); } } And … Read more

Setting a cookie in a WebBrowser control

Looks like there is a better way: Import the InternetSetCookie function: [DllImport(“wininet.dll”, CharSet = CharSet.Auto, SetLastError = true)] static extern bool InternetSetCookie(string lpszUrlName, string lpszCookieName, string lpszCookieData); Create the Cookie object: Cookie temp1 = new Cookie(“KEY1”, “VALUE1”, “/Path/To/My/App”, “https://stackoverflow.com/”); Call InternetSetCookie function to set the cookie for that URL InternetSetCookie(“https://my.url.com/Path/To/My/App”, null, temp1.ToString() + “; expires … Read more

Use cookies from CookieContainer in WebBrowser

You need to make use of InternetSetCookie. Here is a sample… public partial class WebBrowserControl : Form { private String url; [DllImport(“wininet.dll”, CharSet = CharSet.Auto, SetLastError = true)] public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData); public WebBrowserControl(String path) { this.url = path; InitializeComponent(); // set cookie InternetSetCookie(url, “JSESSIONID”, Globals.ThisDocument.sessionID); // navigate webBrowser.Navigate(url); … Read more

Zoom in on a web page using WebBrowser .NET control

There appears to be a solution at IE Zoom that involves overriding AttachInterfaces and DetachInterfaces in the WebBrowser to get a IWebBrowser2 interface, and then calling ExecWB with OLECMDID_OPTICAL_ZOOM. I’ve tried his sample code and it appears to work; the (abridged) relevant class looks like this: using System; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ZoomBrowser { … Read more

Use local images in Webbrowser control

You will need to store your images in the Isolated Storage and then display the images from there. I have put together a sample that you can download from the following location :- www.smartmobiledevice.co.uk/projects/webbrowserimagesample.zip This is based on the MSDN article How to: Display Static Web Content Using the WebBrowser Control for Windows Phone.

Some Elements missing while downloading from HttpWebRequest?

You need to activate the WebBrowser advanced feature for the parsing procedure to complete successfully. When these features are not enabled, the WebBrowser, in standard IE7 emulation, won’t be able to complete the Document. The failure is caused by the high number of scripting errors. I’ve added a class with static methods (WebBrowserAdvancedFetures) to add … Read more

Perform screen-scape of Webbrowser control in thread

You can write private Image TakeSnapShot(WebBrowser browser) { browser.Width = browser.Document.Body.ScrollRectangle.Width; browser.Height= browser.Document.Body.ScrollRectangle.Height; Bitmap bitmap = new Bitmap(browser.Width – System.Windows.Forms.SystemInformation.VerticalScrollBarWidth, browser.Height); browser.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); return bitmap; } A full working code var image = await WebUtils.GetPageAsImageAsync(“http://www.stackoverflow.com”); image.Save(fname , System.Drawing.Imaging.ImageFormat.Bmp); public class WebUtils { public static Task<Image> GetPageAsImageAsync(string url) { var tcs = … Read more

Calling a Javascript function in the C# webBrowser control

Can you specify what failed? My sample below consists of a form with a WebBrowser and a Button. The object called y in the end has the sentence “i did it!”. So with me it works. public partial class Form1 : Form { public Form1() { InitializeComponent(); webBrowser1.DocumentText = @”<html><head> <script type=”text/javascript”> function doIt() { … Read more

How to disable click sound in WebBrowser Control

For IE7 and above, you can use this: int feature = FEATURE_DISABLE_NAVIGATION_SOUNDS; CoInternetSetFeatureEnabled(feature, SET_FEATURE_ON_PROCESS, true); using the following DLL imports private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21; private const int SET_FEATURE_ON_THREAD = 0x00000001; private const int SET_FEATURE_ON_PROCESS = 0x00000002; private const int SET_FEATURE_IN_REGISTRY = 0x00000004; private const int SET_FEATURE_ON_THREAD_LOCALMACHINE = 0x00000008; private const int SET_FEATURE_ON_THREAD_INTRANET = … Read more

Displaying html from string in WPF WebBrowser control

The WebBrowser has a NavigateToString method that you can use to navigate to HTML content. If you want to be able to bind to it, you can create an attached property that can just call the method when the value changes: public static class BrowserBehavior { public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached( “Html”, typeof(string), … Read more