( Index )


Brief Information about the February '17 CSIG Meeting

ACGNJ.exe - An dedicated web browser application - C# with .Net

by Bruce Arnold .

Popup Error


Random Screen Shot

Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs. (Some are FREE!)  During the meeting there will be time for Random Access Questions as well as other discussions.

Here's a brief synopsis of the coming meeting:

It's possible to place a Web page inside your Windows Forms Application using the WebBrowser Class.  If you make the web window as large as your dialog box, you basically get a full browser.  This is what will be demonstrated at the Tuesday night meeting. Only, it will be dedicated to displaying the ACGNJ web site:  http://www.acgnj.org.


This month's program uses Microsoft DOT NET C# code (CLI) to create a Windows Forms Application.  The Forms Class created contains a few methods that we will discuss in detail.  The WebBrowser class is extremely deluxe and is based on the code from Internet Explorer version 11.  As such there are literally hundreds of Properties, Methods, and Events  (Actually 445. ). I plan to discuss only a few of them.  However, due to the relative simplicity of the Dialog Box Application, the meeting will provide and oportunity to learn all aspects of the Windows program design. There are also some hidden challenges for the advanced programmer.  Source code is available as well as an execuitable.

The program uses some of the most sophisticated Dot Net Library functions including the following:

using System
using System.Drawing
using System.Windows.Forms
Mouse Events

There are a number of ways to refer to Microsoft's latest compilers and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 4.5
C++ / C#
Visual Studio Community 2015
Common Language Infrastructure

Sample Code

/* **************************************************************************** Acgnj.cs Version 1.00 B.Arnold 2/21/2017 Object: To use the DOT NET "webBrowser" class to create a dedicated app for displaying the ACGNJ club website. Note: A warning popup message will appear when a new site is rendered. See code at end of file for a "work in progress" attempted solution. **************************************************************************** */ using System; using System.Drawing; using System.Windows.Forms; using System.Text.RegularExpressions; namespace Acgnj { public partial class Form1 : Form { int zoom; Screen mScreen; // Screen working area public Form1() { InitializeComponent(); this.zoom = 100; this.Width = 1200; this.Height = 1000; } // // Center and Adjust the size of the Display Window. Then render the web page. // private void Form1_Load(object sender, EventArgs e) { mScreen = Screen.FromControl(this); if (mScreen.WorkingArea.Right < this.Width) this.Width = mScreen.WorkingArea.Width; if (mScreen.WorkingArea.Bottom < this.Height) this.Height = mScreen.WorkingArea.Bottom; this.CenterToScreen(); this.webBrowser1.Url = new Uri("http://www.acgnj.org"); } // // Display the web address in the lower left corner of the window. // The Web Document Loading starts now. // private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e) { KillPopup(); UpdateFooter(); } // // Restore the proper zoom level. // private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { UpdateFooter(); } // // Change the zoom level via buttons. // private void zoomOUT_Click(object sender, EventArgs e) { zoom -= 20; if (zoom < 20) zoom = 20; UpdateFooter(); } private void zoomIN_Click(object sender, EventArgs e) { zoom += 20; UpdateFooter(); } // // Update the text information on the footer line. // private void UpdateFooter() { this.zoomLevel.Text = String.Format(" {0} %", zoom); this.webBrowser1.Document.Body.Style = String.Format("zoom: {0}%", zoom); this.renderedSize.Text = webBrowser1.Document.Body.ScrollRectangle.Size.ToString(); this.Uri.Text = webBrowser1.Url.ToString(); } // // KILL POPUP ---- WORK IN PROGRESS // /* ******************************************************************* Here's the popup: Message from webpage WARNING: You appear to be using IE11 in IE7 emulation mode. IE emulation modes can behave significantly differently from ACTUAL older versions of IE. PLEASE DON'T FILE BOOTSTRAP BUGS based on testing in IE emulation modes! ******************************************************************* */ // // Object: To erase the code that generates the popup message. // private void KillPopup() // Just return, since this procedure fails to find string. { return; //// GOOGLE REFERENCE: "webBrowser control stop javascript alert from website" //string alertRegexPattern = "alert\\([\\s\\S]*\\);"; ////make sure to only write to webBrowser1.DocumentText if there is a change. ////This will prompt a reloading of the page (and another 'Navigated' event) [see MSDN link] //if (Regex.IsMatch(webBrowser1.DocumentText, alertRegexPattern)) // webBrowser1.DocumentText = // Regex.Replace(webBrowser1.DocumentText, alertRegexPattern, string.Empty); } } } /* **************************************************************************** SAMPLE webBrowser1.DocumentText "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n <meta name=\"description\" content=\"The Amateur Computer Group Group of New Jersey (ACGNJ) is a 501(c)(3) non-profit organization focusing on computer education.\">\n <meta name=\"keywords\" content=\"Main Meeting,Linux,Java,C++,Mobile Devices,Computerized Investing,Window Pains, NJ Gamers,Web Browsers\">\n <meta name=\"author\" content=\"Michael Redlich\">\n <title>ACGNJ</title>\n\n <link rel=\"stylesheet\" href= **************************************************************************** */


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page